iOS推送、3D touch、分享等进入APP的不同跳转方式

1、当前以极光推送为例,如何从通知栏点击进入到APP的不同页面

在APPDelegate.m文件中

实现接受到远程推送的通知方法,在我们点击通知栏的时候,这个方法仍然会走一次(这里介绍的方法是改变root后进行跳转,也可直接跳转)

//IOS 7 Support Required -- 接受到远程通知

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    

    // IOS 7 Support Required

    if (application.applicationState == UIApplicationStateActive) {

        // 转换成一个本地通知,显示到通知栏,你也可以直接显示出一个alertView,只是那样稍显aggressive:)

        UILocalNotification *localNotification = [[UILocalNotification alloc] init];

        localNotification.userInfo = userInfo;

        localNotification.soundName = UILocalNotificationDefaultSoundName;

        localNotification.alertBody = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];

//        localNotification.fireDate = [NSDate date];

        

        [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

        

    } else {

        

        [JPUSHService handleRemoteNotification:userInfo];


        [[AccountManager sharedInstance] changeRootViewControllerWithHome]; //改变rootviewController为主页面(我这里为tabbar的第一个页面)


        MyNavigationViewController *myNavi = self.window.rootViewController.childViewControllers[0]; 拿到当前controller


        if ([AccountManager sharedInstance].isLogin) {

            

            //传入一个消息的model

            MessageListModel *model = [[MessageListModel alloc] init];

            [model setValuesForKeysWithDictionary:userInfo];

            [self addNotification:model]; //在这个方法中设置不同的跳转

            

        } else {

            

            UserLoginViewController *login = [[UserLoginViewController alloc] init];

            [myNavi pushViewController:login animated:YES]; //未登录是的跳转

        }

    }

    completionHandler(UIBackgroundFetchResultNewData);

    

    [self.rootViewController addNotificationCount];

}    

2、3D touch进入到APP的不同页面(这里简单的只有一个跳转,如果需要,可通过shoratitem字段判断)

#pragma mark --- 3D Touch 入口方法

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler

{

    

    [[AccountManager sharedInstance] changeRootViewControllerWithHome];

    

    MyNavigationViewController *myNavi = self.window.rootViewController.childViewControllers[0];

    

    if ([AccountManager sharedInstance].isLogin) {

        

        ExpandViewController *expandVC = [[ExpandViewController alloc] init];

        [myNavi pushViewController:expandVC animated:YES];

        

    } else {

        

        UserLoginViewController *login = [[UserLoginViewController alloc] init];

        [myNavi pushViewController:login animated:YES];

    }

}

另外:也可直接在当前的页面进行不同跳转

只需将以上的rootViewController.childViewControllers[0]改为rootViewController.selectedViewController

列如:

      //跳到登录页面

      UserLoginViewController *loginVC = [[UserLoginViewController alloc] init];

      [((UINavigationController *)tabBarController.selectedViewController) pushViewController:loginVC animated:YES];


你可能感兴趣的:(iOS开发)