实现iOS收到推送消息后跳到指定的页面

########这里离线推送用的极光推送,集成推送这里就不做说明了,根据极光官方文档集成基本没有什么问题。

#######极光推送收到消息的代理方法:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ NSLog(@"尼玛的推送消息呢===%@",userInfo); // 取得 APNs 标准信息内容,如果没需要可以不取 NSDictionary *aps = [userInfo valueForKey:@"aps"]; NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容 NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; NSString *sound = [aps valueForKey:@"sound"]; //播放的声音 // 取得自定义字段内容,userInfo就是后台返回的JSON数据,是一个字典 [APService handleRemoteNotification:userInfo]; application.applicationIconBadgeNumber = 0; [self goToViewControllerWith:userInfo]; }

#######在这里方法里面做跳转
- (void)goToViewControllerWith:(NSDictionary*)msgDic{ //将字段存入本地,因为要在你要跳转的页面用它来判断,这里我只介绍跳转一个页面, NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults]; [pushJudge setObject:@"push"forKey:@"push"]; [pushJudge synchronize]; NSString * targetStr = [msgDic objectForKey:@"target"]; if ([targetStr isEqualToString:@"notice"]) { MessageVC * VC = [[MessageVC alloc]init]; UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:VC];//这里加导航栏是因为我跳转的页面带导航栏,如果跳转的页面不带导航,那这句话请省去。 [self.window.rootViewController presentViewController:Nav animated:YES completion:nil]; } }

提示:跳转到指定页面后(因为有正常操作进入到这个页面,也有点推送消息直接跳转到这个页面),这个动作需要作区分,这里用NSUserDefaults保存了一个push;来区分,pop或者dismiss页面也需要根据这个key来进行操作

实现:

-(void)viewWillAppear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:NO animated:YES]; [super viewWillAppear:YES]; NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults]; if([[pushJudge objectForKey:@"push"]isEqualToString:@"push"]) { //如果是点推送消息进来的做什么操作 //这里需要清空NSUserDefaults NSUserDefaults * pushJudge = [NSUserDefaults standardUserDefaults]; [pushJudge setObject:@""forKey:@"push"]; }else{ //如果是正常操作点进来的做什么操作 } }

你可能感兴趣的:(实现iOS收到推送消息后跳到指定的页面)