Handling Push Notifications Received When App Was Dead, Started Up by Clicking App Icon

WonderboyWonderboy ZAMember ✭✭

Dear Good People,
I am struggling with the handling of Push Notifications received when App is dead. I do receive the notification (banner), but would like to access the notification when I start up the app by clicking on the App icon.
When I start the app up by clicking the banner, I am able to access the notification via the ReceivedNotification method. The problem/question is, how do I access the notification when the app gets started by clicking the App Icon.
Your assistance will be highly appreciated.

Kind regards

Thulani

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    There's no way to receive data from notification, when user click icon to open the applications.
    The only way to handle the remote notification is user opening the app from notification center, when app is on background or closed state. There're two methods you can choose in this situation when app is closed:
    From FinishedLaunching():

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        ...
    
        if (launchOptions != null)
        {
            var userInfor = launchOptions.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey);
        }
    
        return true;
    }
    

    From DidReceiveRemoteNotification():

    public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
    {
        Console.WriteLine(userInfo);
        completionHandler(UIBackgroundFetchResult.NewData);
    }
    

    Or if you have implemented the UNUserNotificationCenter on iOS 11, DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) is adapted.

  • WonderboyWonderboy ZAMember ✭✭

    Dear Landu,
    Are you saying that there is no way of retrieving the notification by clicking the app icon, even if it shows a badge with notification numbers? That is extremely sad.
    I have noted that in
    FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    the value for launchOptions is always null, unless you have clicked the notification banner.

    I beleive most users are likely to click the app icon when they see the badge, compared to clicking on the notification itself.

    Regards

    Thulani

  • LandLuLandLu Member, Xamarin Team Xamurai

    No, exists no such feature. This is designed by Apple.
    The launchOptions won't include notifications information when launching form icon. For the users who want to lauch app from the initial state, clicking icon is a much easier and higher efficiency way.
    Also from the notification center, we will know which single notification has been tapped. It's much more clearly than holding too much data in the launchOptions if there're several notifications from this app.

  • WonderboyWonderboy ZAMember ✭✭

    Thanks again @LandLu .
    One last question which I beleive would be a great workaround. The 'Reminders' notifications on the iPhone seem to be always visible, especially when phone is locked, unlike the other notifications. Is there anything I can do to force my notification to be always visible, just like the Reminder notifications.
    Most notifications tend to get hidded after a few seconds.

    Thanks

  • LandLuLandLu Member, Xamarin Team Xamurai

    I haven't seen this kind of notifications. It seems the app's sever sends the notification again and again until user has responded it.

Sign In or Register to comment.