推送消息出现情景和处理办法
1. 当程序处于关闭状态收到推送消息时,点击图标会调用- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions这个方法,那么消息给通过launchOptions这个参数获取到。
// 判断程序是不是由推送服务完成的
if (launchOptions)
{
NSDictionary* pushNotificationKey = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (pushNotificationKey)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"推送通知"
message:@"这是通过推送窗口启动的程序,你可以在这里处理推送内容"
delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}
2. 当程序处于前台工作时,这时候若收到消息推送,会调用- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo这个方法
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"接收到本地提醒"
message:notification.alertBody
delegate:nil
cancelButtonTitle:notification.alertTitle
otherButtonTitles:notification.alertAction, nil];
[alert show];
//这里,你就可以通过notification的useinfo,干一些你想做的事情了
// application.applicationIconBadgeNumber -= 1;
}
3. 当程序处于后台运行时,这时候若收到消息推送,如果点击消息或者点击消息图标时,也会调用- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary *)userInfo这个方法