0

Im currently working on xamarin form ios app push notification. if app is closed(swiped) then DidReceiveRemoteNotification does not calls.

data payload is like below in server side,

private void SendMessage(string[] MessageTokenArray, string TextMessage)

    {
            var dataIOS = new
                {
                    // to = MessageToken,
                    registration_ids = MessageTokenIOS,
                    content_available = true,
                    priority = "high",
                    data =  new
                    {
                      body = body1,
                      title = eventname,
                      click_action = "OPEN_ACTIVITY_1",
                      priority = "high",
                      tag = "\"1\""
                     },
                     notification = new 
                     {
                        title = eventname,
                        text = TextMessage,
                        sound = 1,
                        vibrate = 1,
                    },
                };
                SendNotificationn(dataIOS);
        }
    }

in xamarin ios

public override bool FinishedLaunching(UIApplication app, NSDictionary options) {

        CrossFirebasePushNotification.Current.RegisterForPushNotifications();
        FirebasePushNotificationManager.Initialize(options, true);
        FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound;

        CrossFirebasePushNotification.Current.OnTokenRefresh += async (s, p) =>
        {
            //save token in server db
        };
        CrossFirebasePushNotification.Current.OnNotificationReceived += async (s, p) =>
        {
            //save data in local db
        };

        CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
        {
            //do something
        };
        return base.FinishedLaunching(app, options);

    }

public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action completionHandler)

{ FirebasePushNotificationManager.DidReceiveMessage(userInfo);

completionHandler(UIBackgroundFetchResult.NewData);

}

  • You can receive the push notification when your app is running but can't receive the remote notification when you app is closed? – nevermore Jun 28 '19 at 02:28
  • yes .. Im not getting notification when app is closed. Do you have any idea to resolve this ? – AshwiniPatkar Jun 30 '19 at 06:06
  • Did you enable the Remote notifications under the background modes capability. Also see here:[ios-notification-when-application-is-closed](https://stackoverflow.com/questions/45057772/ios-notification-when-application-is-closed) – nevermore Jul 01 '19 at 06:09
  • yes I have enabled Remote notifications. – AshwiniPatkar Jul 01 '19 at 10:10
  • yes I have enabled Remote notifications. From the above link, what i understood is if notification open , then only I can get notification data. Otherwise I can not access the data(what if user doesnt not click on notification?? data will lost). For me , I need to store data in sqlite database once notification arrives. – AshwiniPatkar Jul 01 '19 at 10:16
  • The system does not automatically launch your app if the user has force-quit it. See the answers in these two threads:[receive-push-when-app-is-closed](https://stackoverflow.com/questions/26586954/receive-push-when-app-is-closed) and [get-data-from-push-notification-when-app-is-closed-in-ios-and-app-not-running-in](https://stackoverflow.com/questions/27447443/get-data-from-push-notification-when-app-is-closed-in-ios-and-app-not-running-in). – nevermore Jul 02 '19 at 06:49
  • Im not understanding whether we are in same page. above link not able to understand...I have updated above post in payload code, now im getting push notification(in foreground , background and in closed app). but when i close app,Im getting notification, but not able to fetch data payload (I want to store this in sqlite).... Is it possible to do or not. – AshwiniPatkar Jul 02 '19 at 11:57
  • I don't think you can fetch data payload when app is closed. `didReceiveRemoteNotification` method will not call when the application is closed. – nevermore Jul 03 '19 at 07:59
  • I appreciated your all this help. If you get any Idea please let me know. – AshwiniPatkar Jul 03 '19 at 08:49
  • No problem, will update you if I get any idea. – nevermore Jul 03 '19 at 08:56

0 Answers0