didreceiveremotenotification not triggered when app killed on IOS

RafaelAddessoRafaelAddesso BRMember ✭✭
edited March 14 in Xamarin.Forms

Hi all,

I am developing an app that receive some push notifications.

Everything is working good when app is running, is in background or foreground, i receive the push notification and after clicking on it, i am able to open a specific page.

Wherever, when the app is force closed (killed), i receive the notification, but i am not able to process the event click because the didreceiveremotenotification event is not triggered.

Below some code from AppDelegate.cs:

`public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
global::Xamarin.Forms.Forms.Init();
FirebasePushNotificationManager.Initialize(launchOptions,true);
CrossFirebasePushNotification.Current.RegisterForPushNotifications();
LoadApplication(new App());

        return base.FinishedLaunching(application, launchOptions);
    }
    public override void WillEnterForeground(UIApplication uiApplication)
    {
        base.WillEnterForeground(uiApplication);
    }
    public override void OnActivated(UIApplication uiApplication)
    {
        base.OnActivated(uiApplication);
    }

    public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
    {
        FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
    }

    public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
    {
        FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);
    }

    public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
    {
        try
        {
            FirebasePushNotificationManager.DidReceiveMessage(userInfo);
            completionHandler(UIBackgroundFetchResult.NewData);

            NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
            var clickAction = (aps[new NSString("ClickAction")] as NSString).ToString();

            if (UIApplication.SharedApplication.ApplicationState.Equals(UIApplicationState.Active))
            {
                //App is in foreground. Act on it.
            }
            else
            {
                App.Current.MainPage = new ChatPage(clickAction);
            }
            // Do your magic to handle the notification data
            System.Console.WriteLine(userInfo);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Error: " + ex.Message);

        }
    }`

I took a look in some posts related to this one but no one helped me to solve this issue.

Can anyone help me on this?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai
    edited March 14

    I've tested FirebasePushNotificationManager, OnNotificationReceived works properly on my side when app is closed. I've no idea what wrong configurations cause this issue.
    I've also noticed you have posted several cases about this same topic if you do have problems using this plugin.
    You could try libraries for Xamarin.iOS: https://github.com/xamarin/GoogleApisForiOSComponents which is made by Microsoft.
    You could handle the notification coming event in DidReceiveRemoteNotification using these libraries for Xamarin.iOS.

  • RafaelAddessoRafaelAddesso BRMember ✭✭
    > @LandLu said:
    > I've tested FirebasePushNotificationManager, OnNotificationReceived works properly on my side when app is closed. I've no idea what wrong configurations cause this issue.
    > I've also noticed you have posted several cases about this same topic if you do have problems using this plugin.
    > You could try libraries for Xamarin.iOS: https://github.com/xamarin/GoogleApisForiOSComponents which is made by Microsoft.
    > You could handle the notification coming event in DidReceiveRemoteNotification using these libraries for Xamarin.iOS.

    Can you please share some code or sample making it work?
  • LandLuLandLu Member, Xamarin Team Xamurai

    Here is my sample. I removed my GoogleService-Info file. Modify the bundle ID to your own and add your GoogleService-Info to test it on your side.

Sign In or Register to comment.