iOS开发 极光推送收到通知后跳转到指定页面

iOS在开放中,会使用到极光推送,然后收到推送时,往往需要跳转指定的界面,而跳转到指定界面时,又分为程序未杀死情况下的跳转和程序已杀死的跳转,即离线状况下的跳转:


当程序未杀死状况下的条状方法很简单:


// iOS 10 Support

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

    // Required

//LXPMessageBoxViewController是要跳转到的目的页面

//LXPTabBarController是根视图

    LXPMessageBoxViewController *ctl = [[LXPMessageBoxViewController alloc] init];

    LXPTabBarController *tabBar = (LXPTabBarController *)self.window.rootViewController;//获取window的跟视图,并进行强制转换

    if ([tabBar isKindOfClass:[UITabBarController class]]) {//判断是否是当前根视图

        UINavigationController *nav = tabBar.selectedViewController;//获取到当前视图的导航视图

        [nav.topViewController.navigationController pushViewController:ctl animated:YES];//获取当前跟视图push到的最高视图层,然后进行push到目的页面

    }

    NSDictionary * userInfo = response.notification.request.content.userInfo;

    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {

        [JPUSHService handleRemoteNotification:userInfo];

    }

    completionHandler();  // 系统要求执行这个方法

}

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

   

    LXPMessageBoxViewController *ctl = [[LXPMessageBoxViewController alloc] init];

    LXPTabBarController *tabBar = (LXPTabBarController *)self.window.rootViewController;

    if ([tabBar isKindOfClass:[UITabBarController class]]) {

        UINavigationController *nav = tabBar.selectedViewController;

        [nav.topViewController.navigationController pushViewController:ctl animated:YES];

    }

    // Required,For systems with less than or equal to iOS6

    [JPUSHService handleRemoteNotification:userInfo];


}


当程序杀死的情况下,又是另一种方法进行跳转到指定页面:

程序杀死时,进入程序肯定会走

AppDelegate的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法


那么我们首先在这个方法里面判断字典,是经过哪种形式进入的程序


如果是经过推送启动的程序,那么使用这个方法:([LXPAppContext context].notificationUserInfo是把启动返回的字典保存到本地,是一个字典接收)

[LXPAppContext context].notificationUserInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];


也就是我们在这里获取到了是经过什么启动的程序,接下来,我们只需要在首页读取上面获取到的字典,如果字典不为空,则进行指定操作:

比如我们的首页是

#import "LXPBaseHomeViewController.h"




那我们就在这个视图出现时调用以下方法

- (void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

    if ([LXPAppContext context].notificationUserInfo) {//如果是从推送通知唤醒

      

        [LXPAppContext context].notificationUserInfo = nil;//进入这里后要把保存的字典重新设置为nil吧,不然那会不听的执行这个方法

        LXPMessageBoxViewController *ctl = [[LXPMessageBoxViewController alloc] init];

        [self.navigationController pushViewController:ctl animated:YES];//跳转到指定页面

    }

}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值