IOS 通知栏点击跳转指定页面

通过rootView跳转和实例化VC

//如果程序没有运行,点击通知栏推送消息跳转到指定页面。

if (launchOptions) {

        

        NSUserDefaults *pushJudge = [NSUserDefaults standardUserDefaults];

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

        [pushJudge synchronize];

        

        //NSDictionary *userInfo = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

        [self presentViewControllerWithPushInfo];

    }


//如果程序正在运行时

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    NSLog(@"Receive Notify: %@", [userInfo JSONString]);

    NSString *alertStr = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];

//收到推送时程序正在前台运行,则给出一个alert,用户选择查看,跳转到指定页面

    if (application.applicationState == UIApplicationStateActive) {

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", alertStr] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"查看", nil];

        [alertView show];

    }

//收到推送时程序在后台运行,点击通知栏中的推送消息,跳转到指定页面

    if (application.applicationState != UIApplicationStateBackground && application.applicationState != UIApplicationStateActive) {

       

        [self presentViewControllerWithPushInfo];

    }

    

    [application setApplicationIconBadgeNumber:0];

    [BPush handleNotification:userInfo];

}


//收到推送时程序正在前台运行,则给出一个alert,用户选择查看,执行这个方法,并且跳转到指定页面

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex == 1) {

        

        [self presentViewControllerWithPushInfo];

    }

}


//点击推送消息跳转到指定页面的跳转方法

- (void)presentViewControllerWithPushInfo {

    

    NSUserDefaults *pushJudge = [NSUserDefaults standardUserDefaults];

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

    [pushJudge synchronize];


   //这个是我要通过推送跳转过去到页面

    MyOrderListViewController *orderListCtrl = [[MyOrderListViewController alloc] init];

    UINavigationController *pushNav = [[UINavigationController alloc] initWithRootViewController:orderListCtrl];

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

}


注:

    NSUserDefaults *pushJudge = [NSUserDefaults standardUserDefaults];

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

    [pushJudge synchronize];

这个东西是一个辨别标示,在跳转到指定页面后拿到[pushJudge setObject:@"push" forKey:@"push"];从而可以知道是通过推送消息跳转过来的还是正常情况下通过导航栏导航过来的!通过这个“push”标示,如果是通过推送消息进入页面的,则用户可以在页面的(void)viewDidLoad这样写:

    NSUserDefaults *pushJudge = [NSUserDefaults standardUserDefaults];

    if ([[pushJudge objectForKey:@"push"] isEqualToString:@"push"]) {

        

        [self.tabBarController.tabBar setHidden:YES];

        

      //给导航栏加一个返回按钮,便于将推送进入的页面返回出去,如果不是推送进入该页面,那肯定是通过导航栏进入的,则页面导航栏肯定会有导航栏自带的leftBarButtonItem返回上一个页面

        UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(rebackToRootViewAction)];

        self.navigationItem.leftBarButtonItem = leftButton;


- (void)rebackToRootViewAction {

    

//将标示条件置空,以防通过正常情况下导航栏进入该页面时无法返回上一级页面

    NSUserDefaults *pushJudge = [NSUserDefaults standardUserDefaults];

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

    [pushJudge synchronize];

    

    [self dismissViewControllerAnimated:YES completion:nil];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值