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


这个分为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];
                }
            }
        }
    }
}


你可能感兴趣的:(IOS)