iOS推送、3D touch、分享等进入APP的不同跳转方式
2016-07-01 11:56
393 查看
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];
相关文章推荐
- 【CF 应用开发大赛】IT Share(IT分享网)
- 新版本susymenu树形菜单,请大家指教、分享
- javascript实现类似百度分享功能的方法
- 网页上facebook分享功能具体实现
- js实现将选中内容分享到新浪或腾讯微博
- js实现选中页面文字将其分享到新浪微博
- 基于js实现微信发送好友如何分享到朋友圈、微博
- Android ShareSDK快速实现分享功能
- Android编程之微信SDK分享功能过程步骤详细分析
- Android实现分享微信好友及出现闪退的解决办法
- Android编程实现微信分享信息的方法
- Android应用中加入微信分享简单方法
- Android调用微信登陆、分享、支付
- Android AlertDialog实现分享对话框/退出对话框/下载对话框
- 纯JS代码实现一键分享功能
- java实现的新浪微博分享代码实例
- Android使用WebView实现截图分享功能
- Android MenuItem分享