简体   繁体   中英

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

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- 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM