您的位置:首页 > 移动开发 > IOS开发

iOS 点击通知栏消息跳转到指定的页面

2016-05-27 11:10 459 查看
这个分为3种情况
1. 当APP为关闭状态时,点击通知栏消息跳转到指定的页面
2. 当APP在后台运行时,点击通知栏消息跳转到指定的页面
3. 当APP在后台运行时,不会有通知栏提醒,也就不会跳转到指定界面

针对1.的处理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self jumpToViewController:launchOptions];

return YES;
}

#pragma mark —页面跳转
- (void)jumpViewController:(NSDictionary*)tfdic
{
NSDictionary *remoteNotification = [tfdic objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if ([CHPaInterface isUserLogin])
{
for (NSString *tfStr in remoteNotification)
{
if ([tfStr isEqualToString:@"careline"])
{
ViewController *_viewController =  [[ViewController alloc]init];
[_viewController loadAPNSInfoDic:remoteNotification];
UINavigationController *nav= (UINavigationController *)self.window.rootViewController;
[nav pushViewController:_viewController animated:YES];
}
}
}
}


针对2.的处理
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//当APP在前台运行时,不做处理
if( [UIApplication sharedApplication].applicationState == UIApplicationStateActive)
{
}

//当APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面
else if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive)
{
if ([CHPatyInterface isUserLogin])
{
NSLog(@"收到推送:%@",userInfo);
for (NSString *tfStr in userInfo)
{
if ([tfStr isEqualToString:@"careline"])
{
ViewController *_viewController =  [[ViewController alloc]init];
[_viewController loadAPNSInfoDic:userInfo];
UINavigationController *nav= (UINavigationController *)self.window.rootViewController;
[nav pushViewController:_viewController animated:YES];
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: