Firebase PushNotification and LocalNotification iOS

Ángel Rubén Valdeolmos Carmona 586 Reputation points
2021-10-21T20:51:44.453+00:00

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

also implement local notifications as it says here:
https://learn.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)

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,290 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 25,841 Reputation points Microsoft Vendor
    2021-10-22T09:27:53.673+00:00

    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://learn.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows
    https://learn.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.


0 additional answers

Sort by: Most helpful