IOS 通知栏点击跳转指定页面
2016-11-11 14:36
591 查看
通过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];
}
//如果程序没有运行,点击通知栏推送消息跳转到指定页面。
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];
}
相关文章推荐
- iOS 点击远程通知消息,跳转到指定页面 (控制器)
- iOS 点击通知栏消息跳转到指定的页面
- iOS 点击远程通知消息,如何跳转到指定页面(控制器)
- iOS实现在webview页面内点击链接,跳转指定App
- iOS远程推送点击消息跳转到指定页面
- iOS点击推送消息跳转到指定页面
- iOS开发中点击推送跳转到指定页面
- 收到推送通知后页面跳转,当程序在后台,无论进入后台之前在哪个界面,点击收到的推送,跳转到指定界面的2个思路:
- iOS实现在webview页面内点击链接,跳转指定App
- iOS之点击通知栏跳转应用的相关页面
- ios点击链接直接跳转到 App Store 指定应用下载页面
- iOS开发 极光推送收到通知后跳转到指定页面
- iOS APNS 极光推送 点击通知栏跳转应用相应页面
- ios点击链接直接跳转到 App Store 指定应用下载页面
- IOS_简单地页面跳转以及NSNotificationCenter(通知中
- ios 应用中直接跳转到指定app页面 或者 app 评价页面 的方法
- iOS层级跳转(UINavigationController跳转返回到指定的页面)
- iOS跳转到指定页面,而不是简单的返回上一个页面
- iOS 开发之 点击tabbarItem添加是否跳转登录页面判断
- IOS 点击通知消息 跳至对应页面