實(shí)現(xiàn)iOS收到推送消息后跳到指定的頁面

########這里離線推送用的極光推送,集成推送這里就不做說明了,根據(jù)極光官方文檔集成基本沒有什么問題。

#######極光推送收到消息的代理方法:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ NSLog(@"尼瑪?shù)耐扑拖⒛?==%@",userInfo); // 取得 APNs 標(biāo)準(zhǔn)信息內(nèi)容,如果沒需要可以不取 NSDictionary *aps = [userInfo valueForKey:@"aps"]; NSString *content = [aps valueForKey:@"alert"]; //推送顯示的內(nèi)容 NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; NSString *sound = [aps valueForKey:@"sound"]; //播放的聲音 // 取得自定義字段內(nèi)容,userInfo就是后臺(tái)返回的JSON數(shù)據(jù),是一個(gè)字典 [APService handleRemoteNotification:userInfo]; application.applicationIconBadgeNumber = 0; [self goToViewControllerWith:userInfo]; }

#######在這里方法里面做跳轉(zhuǎn)
- (void)goToViewControllerWith:(NSDictionary*)msgDic{ //將字段存入本地,因?yàn)橐谀阋D(zhuǎn)的頁面用它來判斷,這里我只介紹跳轉(zhuǎn)一個(gè)頁面, 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];//這里加導(dǎo)航欄是因?yàn)槲姨D(zhuǎn)的頁面帶導(dǎo)航欄,如果跳轉(zhuǎn)的頁面不帶導(dǎo)航,那這句話請省去。 [self.window.rootViewController presentViewController:Nav animated:YES completion:nil]; } }

提示:跳轉(zhuǎn)到指定頁面后(因?yàn)橛姓2僮鬟M(jìn)入到這個(gè)頁面,也有點(diǎn)推送消息直接跳轉(zhuǎn)到這個(gè)頁面),這個(gè)動(dòng)作需要作區(qū)分,這里用NSUserDefaults保存了一個(gè)push;來區(qū)分,pop或者dismiss頁面也需要根據(jù)這個(gè)key來進(jìn)行操作

實(shí)現(xiàn):

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容