question

Angelru avatar image
0 Votes"
Angelru asked Angelru commented

Firebase PushNotification and LocalNotification iOS

I have the push notifications working with this nuget:
https://github.com/CrossGeeks/FirebasePushNotificationPlugin

also implement local notifications as it says here:
https://docs.microsoft.com/es-es/xamarin/xamarin-forms/app-fundamentals/local-notifications

Everything works fine except in iOS the local notifications, I have to deactivate the one from firebase

 //FirebasePushNotificationManager.Initialize(options, true);



How do I make push and local work? (I am testing in the simulator)

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WenyanZhang-MSFT avatar image
0 Votes"
WenyanZhang-MSFT answered Angelru commented

Hello,

Welcome to our Microsoft Q&A platform!

I check the the source code of FirebasePushNotificationPlugin you used, we can see the following code in RegisterForPushNotifications() method.

 UNUserNotificationCenter.Current.Delegate = CrossFirebasePushNotification.Current as IUNUserNotificationCenterDelegate;

However, when you implement local notifications, the AppDelegate class must specify an iOSNotificationReceiver object as the UNUserNotificationCenter delegate during application startup , so you need add the following code

  UNUserNotificationCenter.Current.Delegate = new iOSNotificationReceiver();

This is why you can't receive the notifications. If you still want to use this plugin, you have to define one delegate, and try to change the the source code of FirebasePushNotificationPlugin . The key point is changing the WillPresentNotification method and DidReceiveNotificationResponse method in FirebasePushNotificationManager.ios.cs.
You could judge RemoteNotification and LocalNotification by UNNotificationTrigger class, and add the LocalNotification code to these two methods, such as the following code

 void ProcessNotification(UNNotification notification)
     {
         string title = notification.Request.Content.Title;
         string message = notification.Request.Content.Body;

         DependencyService.Get<INotificationManager>().ReceiveNotification(title, message);
     }

It's a little hard to be compatible, that is why I do not recommend using third parties. I still try to set two delegate, but it doesn't work. You can keep exploring, If there is anything update, feel free to let me know.

--------------update----------------

I find a similar issue , if you still want to use FirebasePushNotificationPlugin, you could try to customize or report it to FirebasePushNotificationPlugin third-party tool.
If you don't want to use the third party plugin, you could refer to https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows
https://docs.microsoft.com/en-us/xamarin/ios/platform/user-notifications/deprecated/remote-notifications-in-ios

Best Regards,
Wenyan Zhang


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

So how can I make it compatible without the third party plugin?

0 Votes 0 ·

I have edited the answer, you could check it.

0 Votes 0 ·

I accept your answer, but I just noticed that push notifications are not working now. I can't get both of them to work ...

0 Votes 0 ·