iosxcodeswift3push-notificationremote-notifications

Which delegate called first when remote notification arrived, while my app is in killed mode(not in background)


Motive:- I want to store payload of notification stored when notification received by app while it is not in background mode or it is killed mode.

issues:- No delegate calls while app getting notification in killed mode.Please suggest what to do in this situations.


Solution

  • You can't do that when app is killed or quit. But you can retrieve the delivered notifications and process them when app is opened again. You can get the notifications using following process.

    UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
    
        for aNoitfication in notifications
        {
            let payload = aNoitfication.request.content.userInfo
            //process the payload
        }
        DispatchQueue.main.sync { /* or .async {} */ 
            // update UI
        }
    }
    

    P.S: Which is available only on iOS 10 or later