首页 > 代码库 > IOS消息推送情况总结
IOS消息推送情况总结
App没有启动的时候,接受到了消息通知.这个时候操作系统会按默认方式来展示一个alert,在App Icon上标记一个数字
1.当程序处于关闭状态收到推送消息时,点击图标或消息栏会调用- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions2.当程序处于前台工作时,这时候若收到消息推送会调用- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo3.当程序处于后台运行时,这时候若收到消息推送,点击图标或消息栏会调用- (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]; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。