GoogleApisForiOSComponents
GoogleApisForiOSComponents copied to clipboard
Firebase CloudMessaging initialization crashes on iOS
I try to use the Firebase CloudMessaging package to implement push notifications for my XamarinForms app. I did all the required steps (included GoogleService-Info.plist, set it to bundle resource, added the required stuff to Entitlements.plist, registered the app at Firebase etc. etc.).
I was trying the sample intialization code, but as soon as it got to accessing Messaging.SharedInstance (e.g. "Messaging.SharedInstance.Delegate = this" like suggested in the documentation) I get a null object exception. It turns out Messaging.SharedInstance is null, no matter what I do. I also tried the cross geeks plugin, which showed the same behaviour.
I'm stuck - if it's a configuration error I made or some things I did overlook, I have no chance of fixing that because I have no information other than the initialization crashing hard on me.
Could someone help please?
I'm encountering exactly the same behaviour. @woolfman007 Did you manage to find any resolution since posting?
Unfortunately, I was not able to solve it. I tried a bunch of different things, but no luck. At the end of the day, I skipped Firebase entirely for iOS and used a vanilla APNS implementation instead. That was no walk in the park either, but I managed to get it working eventually.
Wow, hopefully can I avoid having to resort to that!
Thanks for quick reply. For anyone else encountering the problem I suspect its an issue when building on Windows. I haven't verified it yet, but I suspect if I build on Mac it may work.
Related: [#452],[#486] and CrossGeeks #388
If I remember correctly, I also tried building on Mac - which did not work either. I'm afraid, we will have to wait until the bug gets fixed and the package gets updated
the same issue, any solution???
Sorry nothing I tried worked. I think Firebase on Xamarin iOS is completely broken atm. I tried building on a Mac instance in our CI/CD pipeline but that didn't work either.
In the end I opted to migrate our push notifications to the Shiny framework - it supports both Firebase and Azure Notification Hubs making it easy to switch between the two. Azure only permits 500 devices for free but it was enough for my needs - and crucially it worked for me on Android and iOS. I'm hoping Shiny will eventually support OneSignal notifications as it has more generous limits in the free tier - I can then switch to that in the future pretty easily with Shiny's great abstraction.
But this is not fixed by updating the firebase ios sdk?
This error only happens when debugging on a physical device, doesn't it? In release mode and from the apple store it works fine, doesn't it?
iOS Simulator doesn't support push notifications. For me it didn't work on the physical iOS device in debug or release mode. I never tried publishing to the app store but I can't see why would that would resolve it. Please post if you find a solution.
At the moment I have an Android and iOS application working with push notifications with this nuget: https://github.com/CrossGeeks/FirebasePushNotificationPlugin
The problem is that debugging on a physical device I get the exception, if you debug in the emulator (you will see that you get the token) although I already know that push notifications do not work in emulator.
But I am afraid to send a new update to the apple store in case the push notifications are no longer received, since in another application that I am working I do not receive a token.
I was trying the CrossGeeks plugin, too and it failed just the same in my case. If I understood that correctly, the plugin is built on top of the Google package anyway, so if this is buggy (which I'm pretty sure it is), the plugin won't work either. Either way, all this feels way too unpredictable and whacky to me, so I went the vanilla route and used the Apple Push service directly, which was no walk in the park, but in the end, it worked perfectly.
You also get the exception on physical device (not on emulator) with the plugin https://github.com/CrossGeeks/GoogleClientPlugin
I am convinced that these problems have to do with the binding of sdk in the configuration. If you compile the application and upload it to the AppStore (You can try TestFlight), you will see that it works fine.
I think it is related to this other post I made, this is the output I get when I try to debug on a physical iPhone from windows: https://developercommunity.visualstudio.com/t/iphone-ios-151-physical-debug/1572333
Yeah I encountered the exception with both the CrossGeeks plugin and the Shiny framework (when using Firebase on iOS) - both depend on this Google package (I agree with @woolfman007 the problem lies here in this underlying component).
In fact, if you try calling the Firebase initialisation calls directly (without CrossGeeks) you get the same exception. I even tried adding Firebase nugets directly to my project but that didn't help.
I also thing you are right @angelru as well... I think these problems are to do with the binding/linking of the SDK somehow. Someone else suggested the problem was caused by Visual Studio's Hot Reload feature not linking correctly (I think I referenced the ticket above) - but I couldn't find a workaround for that either. I guess that would fit with your Test Flight observation where Hot Reload isn't a factor.
I've also encountered the other problem you link to as well... In my case a full solution clean (delete bin and obj folders) and full rebuild resolved that issue - but nothing I did fixed this issue.
So I think we have 2 problems (google and firebase libraries are not up to date and visual studio fails)
Which version of Xamarin.iOS.Firebase.Cloud Messaging contain this issue? And which Xamarin.iOS's version?
https://www.nuget.org/packages/Xamarin.Firebase.iOS.CloudMessaging/4.7.1
@giuseppenovielli
I really don't know if it's a Xamarin.iOS or Xamarin.Firebase.iOS problem. I think it has to do with the sdk linker on the physical iPhone from windows, it also happens with the facebook login, google login. In the emulator it works fine.
@angelru which Xamarin.iOS and Xamarin.iOS.Firebase.Cloud Messaging use now?
@giuseppenovielli https://www.nuget.org/packages/Xamarin.Firebase.iOS.CloudMessaging/4.7.1
I have no problems with push notifications. It is only when trying to install the application on an iPhone physical device in debug mode. But it also happens with the nuget of facebook, google. In the emulator everything is fine. Everything works in AppStore too.
I have read this issue is only on Visual Studio (Windows), when matching with Mac to test a physical device in debug mode.
So i have a MacBook and as i read, i haven't this issue.
When debug in windows to physical device do you have enabled Linker?
Yes, it only happens in Windows with an iPhone connected.
A while ago I opened a ticket: https://developercommunity.visualstudio.com/t/iphone-ios-151-physical-debug/1572333
I'm still getting this issue on visual studio 17.5 connecting to physical iOS device (16.2).
Did anyone manage to find a workaround for this issue? @angelru @TheObliterator @woolfman007
I noticed MS closed the ticket as fixed..
I am getting same issue anyone with a workaround? thanks