iOS开发 极光推送收到通知后跳转到指定页面
2017-05-25 10:22
435 查看
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];//跳转到指定页面
}
}
当程序未杀死状况下的条状方法很简单:
// 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];//跳转到指定页面
}
}
相关文章推荐
- 【iOS开发】iOS极光推送 点击推送消息跳转页面
- iOS开发中点击推送跳转到指定页面
- 收到推送通知后页面跳转,当程序在后台,无论进入后台之前在哪个界面,点击收到的推送,跳转到指定界面的2个思路:
- iOS推送详解(二)收到通知跳到指定页面的处理办法
- iOS 远程推送(极光推送) 根据后台推送内容的不同跳转指定页面(不断更新)
- iOS APNS 极光推送 点击通知栏跳转应用相应页面
- iOS开发关于远程推送页面跳转
- iOS 点击远程通知消息,如何跳转到指定页面(控制器)
- iOS极光推送 点击推送消息跳转页面
- ios推送 程序未启动,收到推送消息,打开应用后跳转到相应的活动页面的代码。
- iOS极光推送 点击推送消息跳转页面
- iOS极光推送 点击推送消息跳转页面
- iOS极光推送 点击推送消息跳转页面
- IOS 通知栏点击跳转指定页面
- iOS极光推送 点击推送消息跳转页面
- iOS收到推送消息后跳到指定的页面
- iOS极光推送 点击推送消息跳转页面
- iOS极光推送 点击推送消息跳转页面
- iOS收到推送后,跳转到某一页面
- 极光推送-点击通知栏跳到指定页面