Launching iOS app when it's not running via silent notifications

给你一囗甜甜゛ 提交于 2019-12-12 02:14:57

问题


According to Apple's official documentation, if one sends a "silent notification", i.e. a notification with content-available: 1 we have

For background download apps: A push notification arrives for an app and the payload of the notification contains the content-available key with a value of 1. The system wakes the app at opportunistic moments to begin downloading new content. For apps downloading content in the background using the NSURLSession class, all tasks associated with that session object either completed successfully or received an error. A download initiated by a Newsstand app finishes.

also it says in that document

Apps are typically woken up at roughly the same time that the user sees the notification but that still gives you more time than you might have otherwise.

How to interpret this? If an app is submitted with a UIBackgroundMode of remote-notification in the plist, does this mean that the app is actually launched in the background if we send a remote notification? Even if the user has restarted the iOS device, and didn't launch our app? Even if the user force-quit our app before?

My question is, how reliable is the above expectation? Has anyone had direct experience with and tested this, and it is true 100% of the time in your experience?


回答1:


From Apple

Configuring a Silent Notification

The aps dictionary can also contain the content-available property. The content- available property with a value of 1 lets the remote notification act as a silent notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.

For a silent notification, take care to ensure there is no alert, sound, or badge payload in the aps dictionary. If you don’t follow this guidance, the incorrectly-configured notification might be throttled and not delivered to the app in the background, and instead of being silent is displayed to the user

iOS is gonna wake up your app and will give you up to 30 seconds to download whatever you need. Keep in mind that notifications are not reliable, so you can't trust they're gonna arrive 100% of the time. If you have really important data to show, you'd need to verify that your app is sync when user opens it. Background fetching is just to improve user experience



来源:https://stackoverflow.com/questions/43034649/launching-ios-app-when-its-not-running-via-silent-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!