ios之极光推送消息收到以后对消息的处理总结

当我们的APP收到推送消息后,通常需要根据推送内容点击消息进入到指定的页面

这里讲一下收到推送消息后的处理,分为三种情况 :1.APP处于前台运行情况下

                                                  2.APP处于后台挂起情况下

                          3.APP未启动情况下

前两种相对好处理一点,我是在didReceiveRemoteNotification方法里接受到消息后发一个通知给MainViewController,跳转界面

具体如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

     

    // Required, iOS 7 Support

    [JPUSHService handleRemoteNotification:userInfo];

    completionHandler(UIBackgroundFetchResultNewData);

    //    NSLog(@"%@",userInfo);

    _notDic = [NSMutableDictionary dictionary];

    [_notDic setObject:userInfo[@"ID"] forKey:@"myID"];

    [_notDic setObject:userInfo[@"PICPATH"] forKey:@"myPic"];

    //判断应用是在前台还是后台

    if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {

         

        //第一种情况前台运行

        NSString *apnCount = userInfo[@"aps"][@"alert"];

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"推送信息" message:apnCount delegate:self cancelButtonTitle:@"查看" otherButtonTitles:@"取消"nil];

        alert.delegate = self;

        [alert show];

         

    }else{

 

      //第二种情况后台挂起时

        [[NSNotificationCenter defaultCenter]postNotificationName:KJPUSHNOT object:nil userInfo:_notDic];

    }

     

}

 

第三种程序未启动时情况下,需要在didFinishLaunchingWithOptions方法里处理,而不能通过通知跳转页面,因为这时MainViewController还没有走viewDidLoad方法,是没办法接受通知的,具体代码如下:

1

2

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

1

2

3

4

5

6

7

8

9

10

    //判断是否是通过点击推送消息进入的APP

    NSDictionary *resultDic = launchOptions[@"UIApplicationLaunchOptionsRemoteNotificationKey"];

    if (resultDic) {//推送进入APP 

     self.window.rootViewController = wantVC;

    }else{//正常进入APP

    self.window.rootViewController = mainVC;

    }

       

    return YES;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值