4

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!

GregorMohorko
  • 2,739
  • 2
  • 22
  • 33
  • What about using this firebase nuget package instead? https://www.nuget.org/packages/Xamarin.Firebase.iOS.CloudMessaging/ It is created by Xamarin. I used it successfully in a previous project. – valdetero Aug 07 '18 at 18:33
  • I have already considered that, but the implementation would then also have to be done separately for Android... The library that I am currently using is implemented using the package that you mentioned. If nobody comes up with a solution, I will definitely try it. – GregorMohorko Aug 07 '18 at 18:38
  • Does anything show up in the device logs? See if the console spits out any system messages about why it killed the app. – valdetero Aug 07 '18 at 19:00
  • I will check it when I get the chance. – GregorMohorko Aug 07 '18 at 19:27
  • it is work : 'LoadApplication(new App()); FirebasePushNotificationManager.Initialize(options, true); CrossFirebasePushNotification.Current.RegisterForPushNotifications(); return base.FinishedLaunching(app, options);' – Ufuk Zimmerman Sep 03 '19 at 11:51

1 Answers1

7

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.

GregorMohorko
  • 2,739
  • 2
  • 22
  • 33
  • Link for GettingStarted guideline is broke! =/ – Leonardo Costa Sep 12 '19 at 18:19
  • 1
    They changed the location of the docs. I've updated the link, check again. – GregorMohorko Sep 13 '19 at 17:05
  • 1
    https://firebase.google.com/docs/cloud-messaging/ios/client#upload_your_apns_authentication_key @GregaMohorko I have also combined your approach with this article and it works for me. – S. Koshelnyk Dec 25 '19 at 17:10
  • Did you remove the FirebasePushNotificationPlugin from the iOS project or the main Forms project? Because I am using the FirebasePushNotificationPlugin in my forms project and it works for my android project. – Bedir Jun 09 '21 at 19:23
  • I removed it from the main Forms project and started using Xamarin.Firebase.iOS.CloudMessaging in both Android and iOS. – GregorMohorko Jun 10 '21 at 08:03
  • When trying to use the Xamarin.Firebase.iOS.CloudMessaging `Messaging.SharedInstance.Delegate = this;` gives an Object reference not set to an instance of an object Error – Bedir Jun 10 '21 at 19:26