在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];
}
#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];
}
}
//跳到登录页面
UserLoginViewController *loginVC = [[UserLoginViewController alloc] init];
[((UINavigationController *)tabBarController.selectedViewController) pushViewController:loginVC animated:YES];