简体   繁体   中英

Is a iOS silent notification received when the app is killed

when sending a background push with "content-available": "1" , to an app that is killed by the user, the application is not launched into the background mode and the application:didReceiveRemoteNotification:fetchCompletionHandler: is not called as the Apple doc say :

Use this method to process incoming remote notifications for your app. [...]In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it.

My question is: Is there is any way to access this silent push payload the next time the user starts the application?

I tried using the launchOptions of the didFinishLaunchingWithOptions method but they do not contain the push payload.

NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

My use case is that I rely only on the push channel to receive data to the app but the app cannot pull them.

Short answer is: no, you cannot.

You also won't be able to use VoIP pushes, the only option would be to use regular pushes with a push notification service extension. Share a keychain between your app and this extension, save the push payload in the keychain when receiving a notification and retrieve it with your app when it enters foreground. Downside is you will need to present a visual notification to the user, but it can be silent, and you can choose to present whatever text you want (the best option will depend on what your app does and what's the purpose of this notification).

You may use a VoIP Push message, see here:

Voice Over IP (VoIP) Best Practices

There are many advantages to using PushKit to receive VoIP pushes:

  • [...]
  • Your app is automatically relaunched if it's not running when a VoIP push is received.
  • [...]

Be aware, that your app must have background mode with VoIP capability enabled, which may be an issue for app store approval if misused.

Looking at the documentation, it seems like you should implement this method:

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

Within that method, write your code to store the payload (userInfo). Maybe store it in the userDefaults temporarily. Then when the application launches, check to see if the payload is available.

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