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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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需要进行修改

以上是关于iOS极光推送跳转到指定页面的主要内容,如果未能解决你的问题,请参考以下文章

iOS:极光推送控制器跳转

iOS远程推送点击消息跳转到指定页面

iOS极光推送 点击推送消息跳转页面

点击极光推送,实现跳转

怎样做点击推送消息,跳转到指定页面

iOS-iOS10极光推送的使用