关于静默推送的几个点

1、静默推送是否可以唤起被杀掉的自身app?

答:非用户杀死的情况可以唤起,但是有限制条件:需要 Target - capabilities - Background Modes 勾选 Remote notifications,这样 app 就拥有了「后台应用刷新」的开关,低电量模式会自动关闭该开关

2、静默推送拉起被系统杀掉的自身app的流程是什么?

答:main() ->

​ UIApplicationMain() ->

​ application: willFinishLaunchingWithOptions: ->

​ application: didFinishLaunchingWithOptions: ->

​ applicationDidEnterBackground:

​ application:didReceiveRemoteNotification:fetchCompletionHandler:
​ ​
​ ​

3、如果没有app没有被系统杀死,只是 suspend(挂起) 状态,流程又是什么样的?

​ 答:只会执行 application:didReceiveRemoteNotification:fetchCompletionHandler:

4、唤起之后 app 会发生什么?

​ 答:唤起之后会拥有 30 秒的后台运行时间,所以你的操作要控制在这个时间之内,越短越好,执行完操作立刻调用 fetchCompletionHandler()

5、 静默推送唤起app和用户主动启动app(点击通知、Icon)有什么区别,怎么分辨?

​ 答:用户主动启动app的流程是 launched into foreground,而静默推送唤起app的流程是 launched into background,分辨方式:在 application:willFinishLaunchingWithOptions: 或 application:didFinishLaunchingWithOptions:方法里检查 application.applicationState 参数,前者为 UIApplicationStateBackground,后者为 UIApplicationStateInactive.

​ 附主动启动的流程图:

6、静默推送可以无限制发送吗?

​ 答:文档说明静默推送是系统低优先级且不保证送达,频率不要超过 2-3 次/小时

7、静默推送实际使用还有什么要注意的地方吗?

​ 答:因为会走 launch 流程,请注意 app 的数据统计,包括但不限于 DAU(日活)

8、 还有哪些方式可以唤起被系统杀掉的 app(自身)?

​ 答:

Xcode background mode UIBackgroundModes value Description
Audio and AirPlay audio The app plays audible content to the user or records audio while in the background. (This content includes streaming audio or video content using AirPlay.)The user must grant permission for apps to use the microphone prior to the first use; for more information, see Supporting User Privacy.
Location updates location The app keeps users informed of their location, even while it is running in the background.
Voice over IP voip The app provides the ability for the user to make phone calls using an Internet connection.
Newsstand downloads newsstand-content The app is a Newsstand app that downloads and processes magazine or newspaper content in the background.
External accessory communication external-accessory The app works with a hardware accessory that needs to deliver updates on a regular schedule through the External Accessory framework.
Uses Bluetooth LE accessories bluetooth-central The app works with a Bluetooth accessory that needs to deliver updates on a regular schedule through the Core Bluetooth framework.
Acts as a Bluetooth LE accessory bluetooth-peripheral The app supports Bluetooth communication in peripheral mode through the Core Bluetooth framework.Using this mode requires user authorization; for more information, see Supporting User Privacy.
Background fetch fetch The app regularly downloads and processes small amounts of content from the network.
Remote notifications remote-notification The app wants to start downloading content when a push notification arrives. Use this notification to minimize the delay in showing content related to the push notification.

参考资料:

1、Strategies for Handling App State Transitions

2、Pushing Updates to Your App Silently

3、Background Execution

4、Multitasking

显示 Gitment 评论