Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.iOS: Firebase push notifications not working

I am developing a Xamarin.Forms application with Xamarin.Android and Xamarin.iOS clients. For push notifications, I am using FirebasePushNotificationPlugin library. It works perfectly on Android, but not on iOS.

On iOS the app simply closes down after the request to use push notifications. So: the "Allow/Don't allow" popup is shown, and when the user clicks on Allow, the app closes down. No exception is thrown or anything.

I have done every step in the setup instructions, but just to double-check, I will show you screenshots of everything:

  1. Firebase console: I have registered my iOS app on the Firebase console and inputted all required fields (App ID, Bundle ID, App Store ID, App ID Prefix). I have also uploaded the APNs Authentication Key (but no certificates).

Firebase Console app Firebase Console app configuration

  1. NuGet: I have added Plugin.FirebasePushNotification package to both Xamarin.Forms and Xamarin.iOS projects.

VisualStudio NuGet packages

  1. GoogleService-Info.plist: I have added GoogleService-Info.plist (that I got from the Firebase console) to the Xamarin.iOS project and set its Build Action to BundleResource.

VisualStudio GoogleService-Info.plist Properties

  1. Info.plist: I have enabled remote notification background mode and added FirebaseAppDelegateProxyEnabled (and set it to No) in Info.plist.

Info.plist

  1. Entitlements.plist: I have added production aps-environment entitlement.

Entitlements.plist

It is production (and not development) because I cannot run and debug the app, so the app is actually being uploaded every time to the App Store Connect and tested with TestFlight as an internal tester.

  1. Xamarin.iOS AppDelegate: I initialize the package in AppDelegate.FinishedLaunching method, right after LoadApplication(new App());. The false parameter means that it will not auto register for notifications (it will be registered later manually).

Xamarin.iOS AppDelegate

I also override methods RegisteredForRemoteNotifications, FailedToRegisterForRemoteNotifications, DidReceiveRemoteNotification and call respected methods (as stated in the Getting Started instructions).

  1. Xamarin.Forms: Now this is when all goes to hell on iOS. When it calls CrossFirebasePushNotification.Current.RegisterForPushNotifications();, it shows the "Allow/Don't allow" popup, and after the user clicks "Allow", the app simply closes. No exception is thrown or anything (well, at least nothing gets caught in the try/catch statement). The app simply shuts down.

Xamarin.Forms App.xaml.cs

The interesting thing maybe is, that the FCM token is already (successfuly) created before all this and if I send a push message to that token (of that iOS app), the Firebase server returns success. So I'm guessing that the Firebase part is correct, but there is something wrong with the iOS and/or the library?

Any advice whatsoever will be greatly appreciated!

like image 515
GregorMohorko Avatar asked Mar 05 '23 16:03

GregorMohorko


1 Answers

For anyone reading this: I have solved this problem by removing the FirebasePushNotificationPlugin library, which apparently doesn't work on iOS. I have then implemented the notifications using the Xamarin.Firebase.iOS.CloudMessaging package instead, following this GettingStarted guideline.

like image 151
GregorMohorko Avatar answered Mar 16 '23 03:03

GregorMohorko