极光推送页面跳转

近几天我们公司开发项目要求用到极光推送。
于是乎看了看 极光 的官方文档,写的很粗糙,但是总体还是不错的。
我这里就简单说说关于推送的跳转问题,因为在一些技术群里面有人这样问过我。

#pragma mark -- 程序点击推送消息进入的方法
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    // Required
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
        [JPUSHServicehandleRemoteNotification:userInfo];
        
         [selfpushToViewControllerWhenClickPushMessageWith:userInfo]; //跳转页面
    }
    completionHandler();  // 系统要求执行这个方法
}
#pragma mark -- 程序跳转方法
-(void)pushToViewControllerWhenClickPushMessageWith:(NSDictionary*)msgDic{
    
    //将字段存入本地,因为要在你要跳转的页面用它来判断
   NSUserDefaults*pushJudge = [NSUserDefaultsstandardUserDefaults];
  //  [pushJudge setObject:@"push"forKey:@"push"];
//判断后台传送的标示(用于跳转哪一个页面的判断)
    if ([[msgDicobjectForKey:@"type"]isEqualToString:@"active"]){
//得到根部控制器
        TabBarController *hxl=(TabBarController *)self.window.rootViewController;
//得到控制器中的导航栏
        UINavigationController *nav=hxl.selectedViewController;
//得到导航栏对应的控制器
        UIViewController  *controller=(UIViewController *)nav.visibleViewController;
//进行跳转页面
        TSProductDetailViewController *pro=[[TSProductDetailViewControlleralloc]init];
        
         pro.detailid=[[msgDicobjectForKey:@"id"]integerValue];        
        [controller.navigationControllerpushViewController:pro animated:YES];
      
    }elseif ([[msgDicobjectForKey:@"type"]isEqualToString:@"dynamics"]){
        TabBarController *hxl=(TabBarController *)self.window.rootViewController;
        hxl.selectedIndex=2;
    }
}
#pragma mark iOS 10 前台收到通知(远程推送本地通知)
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
        /// iOS10处理远程推送
        [JPUSHServicehandleRemoteNotification:userInfo];
        /// 前台收到推送的时候转成本地通知 ===========================
        [self popAlert:userInfo];
        
    }else{
        /// iOS10处理本地通知添加到通知栏 ==============================
        completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
        
        
    }
    // 需要执行这个方法,选择是否提醒用户,有BadgeSoundAlert三种类型可以选择设置
}
//在前台的时候 我这里就直接弹出提示框
-(void)popAlert:(NSDictionary *)pushMessageDic{
    NSLog(@"%@",pushMessageDic);
    NSString *title;
    if([[pushMessageDicobjectForKey:@"type"]isEqualToString:@"active"])
    {
     title=@"您有新的活动推送";
        [JCAlertViewshowTwoButtonsWithTitle:titleMessage:             [[pushMessageDicobjectForKey:@"aps"]objectForKey:@"alert"]ButtonType:JCAlertViewButtonTypeCancelButtonTitle:@"取消"Click:^{
            
        } ButtonType:JCAlertViewButtonTypeDefaultButtonTitle:@"查看"Click:^{
            [selfpushToViewControllerWhenClickPushMessageWith:pushMessageDic];
            
        }];
    }elseif([[pushMessageDic objectForKey:@"type"]isEqualToString:@"dynamics"]){
        title=@"您有新的评论消息";
        [JCAlertViewshowOneButtonWithTitle:titleMessage:[[pushMessageDicobjectForKey:@"aps"]objectForKey:@"alert"]ButtonType:JCAlertViewButtonTypeCancelButtonTitle:@"取消"Click:^{
            
        }];
      
    }
    
   
}

猜你喜欢

转载自blog.csdn.net/huanglinxiao/article/details/64128869
今日推荐