IOS消息推送情况总结

 

 App没有启动的时候,接受到了消息通知.这个时候操作系统会按默认方式来展示一个alert,在App Icon上标记一个数字

1.当程序处于关闭状态收到推送消息时,点击图标或消息栏会调用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2.当程序处于前台工作时,这时候若收到消息推送会调用
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

3.当程序处于后台运行时,这时候若收到消息推送,点击图标或消息栏会调用
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

针对1种情况代码
if (launchOptions) {
        NSDictionary* pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
        //此处必须用stringWithFormat转换下
        if (pushInfo != nil) {
            
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App关闭" message:[NSString stringWithFormat:@"%@",pushInfo] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
        }
    }

针对2,3种情况代码
if ([[userInfo objectForKey:@"aps"] objectForKey:@"alert"]!=NULL) {
        // 当程序处于前台工作时,这时候若收到消息推送处理
        if(application.applicationState == UIApplicationStateActive){
            
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App前台运行" message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
        else  //当程序处于后台运行时,这时候若收到消息推送处理
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App后台运行" message:[NSString stringWithFormat:@"%@",userInfo] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            
        }
    }

 

IOS消息推送情况总结,布布扣,bubuko.com

IOS消息推送情况总结

上一篇:android里面的进程回收机制[转载]


下一篇:Android TabHost 的美化与设计