iOS极光推送跳转到指定页面

首先要初始化sdk,官方文档上有

 

[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)  categories:nil];

 

    [JPUSHService setupWithOption:launchOptions appKey:@"" channel:@"Publish channel" apsForProduction:NO];

 

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

 

    //alias需要看自己的实际情况赋值

        [JPUSHService setTags:nil alias:nil fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {            

 

        }];

 

    });

 

 

 

APPDelegate中加入方法

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    [JPUSHService handleRemoteNotification:userInfo];

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

    completionHandler(UIBackgroundFetchResultNewData);

    if (application.applicationState == UIApplicationStateActive) {

       //这里写APP正在运行时,推送过来消息的处理

        

    } else if (application.applicationState == UIApplicationStateInactive ) {

//APP在后台运行,推送过来消息的处理

        [self goToMssageViewControllerWith:userInfo];

 

    } else if (application.applicationState == UIApplicationStateBackground) {

//APP没有运行,推送过来消息的处理

        [self goToMssageViewControllerWith:userInfo];

    }

}

//跳转方法

- (void)goToMssageViewControllerWith:(NSDictionary*)msgDic{

    //将字段存入本地,在要跳转的页面用它来判断

    NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults];

    [pushJudge setObject:@"push"forKey:@"push"];

    [pushJudge synchronize];

    if ([msgDic[@"type"]isEqualToString:@"Notification_cabinet"]) {

  //这里写要跳转的controller

    UserOrderListViewController * VC = [[UserOrderListViewController alloc]init];

    UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:VC];

    [self.window.rootViewController presentViewController:Navanimated:YES completion:nil];

    } else if ([msgDic[@"type"]isEqualToString:@"Message_notice"]) {

        RecommendViewController *vc = [[RecommendViewController alloc] init];

        UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:vc];

        [self.window.rootViewControllerpresentViewController:Nav animated:YES completion:nil];

        

    } 

}

在要跳转的页面中的ViewDidLoad方法中加入

 NSUserDefaults*pushJudge = [NSUserDefaults standardUserDefaults];

    if([[pushJudgeobjectForKey:@"push"]isEqualToString:@"push"]) {

        [self.navigationController setNavigationBarHidden:NOanimated:YES];

        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@""]style:UIBarButtonItemStylePlain target:selfaction:@selector(rebackToRootViewAction)];

    }

具体情况根据自己的APP需要进行修改

转载于:https://www.cnblogs.com/huihuihui/p/5865340.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值