zoukankan      html  css  js  c++  java
  • 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];
                
            }
        }
  • 相关阅读:
    js ++i和i++的区别
    js斐波那契数列
    js二分查找算法
    js查找、自组织数据
    查找数组最小值、最大值
    CSS布局(圣杯、双飞翼、flex)
    碰撞检测实现
    ECharts注释
    购物查看放大
    动手封装一个滚轮事件吧!
  • 原文地址:https://www.cnblogs.com/joesen/p/3921603.html
Copyright © 2011-2022 走看看