• 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];
                
            }
        }
  • 相关阅读:
    Java中参数传递时值传递的机制分析
    掰碎了讲中文编码
    掰碎了讲换行符和回车符
    创建父子控制器
    分页(进行封装处理)
    五:面向对象的三大特性:封装、继承、多态
    iOS9弹框的最新两种方式(解决控制器以外的类无法弹出的问题)
    各类报错汇集
    NBA季后赛结果预测
    十:类的本质及isa指针和元类的简单介绍
  • 原文地址:https://www.cnblogs.com/joesen/p/3921603.html
Copyright © 2020-2023  润新知