关于iOS Push Notification响应的问题

当server向client投送通知时,client有以下几种情况:

1. 应用程序处于关闭状态,这时通知被显示;无论是点击应用图标还是点击通知,系统都会启动应用,并调用其代理方法,(application:didFinishLaunchingWithOptions:),通过launchOptions来传递通知。

if (launchOptions) {

NSDictionary* pushNotificationKey = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

        if (pushNotificationKey) {

            //这里定义自己的处理方式

        }

}

2. 应用程序处于background状态,这时通知被显示。如果点击通知,应用调用application:didReceiveRemoteNotification:方法或application:didReceiveLocalNotification:方法,如果点击应用图标,则不会自动执行上面的方法。

 

3. 应用程序处于foreground状态,这时通知不会被显示。应用程序直接调用(因为应用在前台)其代理函数application:didReceiveRemoteNotification:方法或application:didReceiveLocalNotification:方法,传递响应的通知对象。

posted on 2015-06-15 14:55  码农之上~  阅读(230)  评论(0编辑  收藏  举报

导航