码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2016-09-12 17:14:49      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

首先要初始化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极光推送跳转到指定页面

标签:

原文地址:http://www.cnblogs.com/huihuihui/p/5865340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!