iOS Push Notification

项目需要,写了一篇绕口令一般的东西,算作这两天的总结吧。

iOS Push Notification

需要考虑的情况有以下几种:

1,静默推送(silent push)和非静默推送;

2,iOS系统>= iOS 10,和< iOS 10;

3,App处于前台(foreground,active),后台(background,inactive,suspend)和close(manually killed,swiped out)


处理Push Notification的delegate有如下几个:

A,application: didReceiveRemoteNotification:fetchCompletionHandler

B,userNotificationCenter:willPresentNotification: withCompletionHandler

C,userNotificationCenter:didReceiveNotificationResponse

D,application:didReceiveLocalNotification

E,cancelLocalNotification:


(非silent push使用APN test,silent push使用我自己的静默推送服务)

Situation 1:非silent push,foreground,iOS 10

收到remote notification后,调用B

Situation 2:非silent push,background,iOS 10

收到remote notification后,响,弹出横幅,消息列于通知中心托盘,选某action后,调C

Situation 3:非silent push,close,iOS 10

同Situation 2

======

Situation 7:非silent push,foreground,< iOS 10

收到remote notification后,调用A

Situation 8:非silent push,background,< iOS 10

收到remote notification后,响,弹出横幅,消息列于通知中心托盘,选action后,调A

Situation 9:非silent push,close,< iOS 10

同Situation 8

======

Situation 4:silent push,foreground,iOS 10

收到remote notification后,调A

从push server获取消息后,发送一个Local Notification

立即收到此Local Notification后,调B

Situation 5:silent push,background,iOS 10

收到remote notification后,调A

从push server获取消息后,发送一个Local Notification。

此Local Notification会响,弹出横幅,消息列于通知中心托盘,选action后,调C

Situation 6:silent push,close,iOS 10

没有任何反应

======

Situation 10:silent push,foreground,< iOS 10

收到remote notification后,调A

从push server获取消息后,发送一个Local Notification

立即收到此Local Notification后,调D。

通知中心托盘会展示此notification,可以调用E从托盘中删除action

Situation 11:silent push,background,< iOS 10

收到remote notification后,调A

从push server获取消息后,发送一个Local Notification。

此Local Notification会响,弹出横幅,消息列于通知中心托盘,选此action后,调D

Situation 12:silent push,close,< iOS 10

没有任何反应


总结:

1,在close状态下,silent push不能唤醒App,也就是收到silent push后,App没有任何反应;

2,Close或background状态下,收到非silent push会响,弹出横幅,消息展示于通知中心托盘,从托盘点选action,会唤醒(启动)App;

3,< iOS 10,收到silent push后,无论foreground或background,都调用A,发送local notification后,都在通知中心托盘展示。不同的是,foreground会立即调用D,而background是在托盘选中action后调用D;

4,< iOS 10,收到非silent push后,foreground直接调用A,background或close时,在通知中心托盘选action后,调用A;

5,由3,4可知,< iOS 10时,只要是remote notification,无论是否为silent push,都从调用A开始;

6,iOS 10,收到silent push后,无论foreground或background,都调用A,发送local notification后,foreground不展示在通知中心托盘,foreground会立即调用B,而background是在托盘中选action后,调用C;

7,由3,6可知,只要是silent push,无论是否为iOS 10,以及无论是foreground或background,都会调用A;

8,iOS 10,收到非silent push后,foreground直接调用B,background或close时,在通知中心托盘选action后调用C;

9,由6,8可知,iOS 10在foreground时收到notification,无论是remote还是local都会调用B,在background(close)时,无论是remote还是local,在通知中心托盘选action后,都会调用C。

你可能感兴趣的:(iOS Push Notification)