2
votes

I have to locally store Title and Body of all the notifications coming in my iOS app and display those in a notifications screen. I'm able to store all the notification tapped by using these-

This gets called when the app is in not running state or killed when the push notification is tapped-

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {...}

This gets called when app is running in foreground or background and push notification is tapped-

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {...}

My question is how to store notifications without tapping on notifications. I want to store the notifications even if the notification is dimissed/cleared by user.

I know this method is called when app is active and in the foreground and push notification comes-

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {..}

How to handle push notification data without tapping on it when the app is in background or not running state?

1
AFAIK it is not possible to handle notification when your app is not in a running state - at least if you don't use VOIP. I had a quite similar issue and was wrote a question here (with no success) stackoverflow.com/questions/51055491/…Teetz
@Teetz Is there a way to handle the notifications data when the user opens the app next time?kumarsiddharth123
I am not 100% sure but i don't think so. AFAIK apps that do that are storing their push notifications on their backend-server and ask the backend at app start to get all the remote notification data.Teetz

1 Answers

3
votes

1- If the app isn't running then no way to wake up the app only with ( VOIP )

2- if in background then add this key to the sended payload

"content_available": true

And enable RemoteNotifications from app capabilities