应用接收push推送通知的几种情况,高人帮忙看看理解是否有误

chenxin 2012-01-12 14:54

应用接收push推送通知的几种情况,高人帮忙看看理解是否有误

这周在研究iOS的推送通知功能。以我自己的理解和试验,设备接到apns发来的通知,应用处理通知有以下几种情况:
1. 应用还没有加载
这时如果点击通知的显示按钮,会调用didFinishLaunchingWithOptionsdidReceiveRemoteNotification两个方法。
如果点击通知的关闭按钮,再点击应用,只会调用didFinishLaunchingWithOptions方法。
2. 应用在前台(foreground)
这时如果收到通知,会触发didReceiveRemoteNotification方法。
3.应用在后台
此时如果收到通知,点击显示按钮,会调用didReceiveRemoteNotification方法。
点击关闭再点击应用,则上面两个方法都不会被调用这时,只能在applicationWillEnterForeground或者applicationDidBecomeActive方法里,根据发过来通知中的badge进行判断了。

需要注意的是,应用在后台运行一段时间后,有可能被系统终止,这时再接收通知,情况就与第一条一样了。


还请高手指教一下,是否理解有误。另外还请问一下applicationWillEnterForeground与applicationDidBecomeActive两个方法有什么区别呢?上面的情况使用那种方法更合适,或者都不对,有其他方法?



 

mangel 2012-02-07 12:10
同求真相,等待高手

 

110440 2012-02-07 14:56
1. 应用还没有加载
这时如果点击通知的显示按钮,didFinishLaunchingWithOptions里可以到得通知,didReceiveRemoteNotification方法应该没调用。
如果点击通知的关闭按钮,再点击应用,不再会调用didFinishLaunchingWithOptions方法,这时通知获取不到了,,不知我有没说错,

 

mangel 2012-02-23 09:32
楼上的正解。现在就是不知道怎么区别通过推送消息的view按钮启动应用还是直接点icon启动应用。

 

destiny_aqua 2012-02-27 22:47
留着之后看。

 

sygong 2012-04-06 17:10
请问你解决了吗?我现在也有这个疑惑

 

mangel 2012-04-08 20:57
呵呵,已经解决了。看我这个帖子 http://www.cocoachina.com/bbs/read.php?tid=94399

 

sygong 2012-04-10 11:22
好的 

 

book 2013-02-20 16:36
mark 一下 很有用的

 

xsx_tide 2013-05-16 15:14
mark 一下 很有用的

 

墓志铭123 2013-05-22 10:33
通知 就要用到了 先收藏了 多谢楼主分享

 

xsx_tide 2013-06-20 13:10
http://www.raywenderlich.com/zh-hans/24731/%E8%8B%B9%E6%9E%9C%E6%B6%88%E6%81%AF%E6%8E%A8%E9%80%81%E6%9C%8D%E5%8A%A1%E6%95%99%E7%A8%8B%EF%BC%9A%E7%AC%AC%E4%B8%89%E9%83%A8%E5%88%86

 

xsx_tide 2013-06-25 14:28
0 没有推送 就会调用 didFinishLaunchingWithOptions
if(launchOptions != nil){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTWO" message:@"请您重新登陆"
                                                       delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        [alert release];
          NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
          if (dictionary != nil){
             [self changeAppImage];
          }
     }else{
    //会调用这里面的
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTWOthree" message:@"请您重新登陆"
                                                        delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
         [alert show];
         [alert release];
          [self changeAppImage];
}

1. 应用还没有加载 直接点启动
这时如果点击通知的显示按钮,会调用didFinishLaunchingWithOptions和didReceiveRemoteNotification两个方法。
if(launchOptions != nil){
//会调用这里面的
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTWO" message:@"请您重新登陆"
                                                       delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        [alert release];
          NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
          if (dictionary != nil){
             [self changeAppImage];
          }
     }else{
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTWOthree" message:@"请您重新登陆"
                                                        delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
         [alert show];
         [alert release];
            [self changeAppImage];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTwoThreeFour" message:@"请您重新登陆"
                                                   delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
    [alert release];
    [self changeAppImage];
}

这时如果点击关闭 在点击应用App  会调用didFinishLaunchingWithOptions

if(launchOptions != nil){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTWO" message:@"请您重新登陆"
                                                       delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        [alert release];
          NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
          if (dictionary != nil){
             [self changeAppImage];
          }
     }else{
    //会调用这里面的
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTWOthree" message:@"请您重新登陆"
                                                        delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
         [alert show];
         [alert release];
          [self changeAppImage];
}


2. 应用在后台加载 
1) 直接点启动
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oneTwoThreeFour" message:@"请您重新登陆"
                                                   delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
    [alert release];
    [self changeAppImage];
}
2) 关闭在点App应用启动

 

utmost2000 2014-03-13 13:34
iOS7 适合用吗?

 

yjfje 2014-04-03 10:22
mark 一下 很有用的

 

 

二胡 2014-06-18 19:09
直接一步到位用腾讯信鸽推送,不用那么麻烦自建系统了:http://xg.qq.com/

posted on 2014-08-27 14:31  鬼手渔翁  阅读(375)  评论(0)    收藏  举报

导航