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需要进行修改

posted @ 2016-09-12 16:46  灰灰灰  阅读(4507)  评论(0编辑  收藏  举报