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

iOS 点击远程通知消息,如何跳转到指定页面(控制器)

2016-03-07 17:02 555 查看
可能大家对跳转到任意控制器的理解有点不同。我自己的做法是通过通知来进行跳转的。appdelegate代理中接收到消息,将userInfo消息通过通知传出去,再此期间,需将跳转的控制器获取出来,接着其实就是获取你点击的某个控件比如cell的id传到那个控制器。然后在该控制器接收通知

就我自己的项目来说:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (application.applicationState == UIApplicationStateActive) {
NSLog(@"active");
//程序当前正处于前台
[application setApplicationIconBadgeNumber:0];

NSString *messageAlert = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"远程通知" message:messageAlert delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"前往", nil];
alertView.delegate = self;

[alertView show];
// 8秒后将退出弹框
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(8.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[alertView dismissWithClickedButtonIndex:0 animated:YES];

});
}
else if(application.applicationState == UIApplicationStateInactive)
{
NSLog(@"inactive");
//程序处于后台

[[NSNotificationCenter defaultCenter]postNotificationName:@"123456" object:nil userInfo:userInfo];

}
// IOS 7 Support Required
[APService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}

在你首页控制器的添加通知,并且跳转到每个控制器
- (void)viewdidload
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pushNotification:) name:@"123456" object:nil];

}
- (void)pushNotification:(NSNotification *)notification
{
NSDictionary *dict = notification.userInfo;

// kpiid  其实就是后台传出来需要点击cell的id
GTLog(@"===notification===%@",[dict valueForKey:@"kpiid"]);

[self selectKPIModuleId:[[dict valueForKey:@"kpiid"] integerValue]];
}

/************************************************
*
*
*  点击相对应的kpiid模块,跳转到相对应的kpi控制器
*
*
************************************************/
- (void)selectKPIModuleId:(int)kpiid     // 此处是tableview  didselect方法中单独提取的方法
{

//销售利润
if(kpiid==1){
ProfitViewController *pyc=[[ProfitViewController alloc] initWithNibName:@"ProfitViewController" bundle:nil];
[(UINavigationController *)self.mm_drawerController.centerViewController pushViewController:pyc animated:YES];
[[TimeTool sharedTimeTool] timeToolBTypeOfStartWhenIntoViewCurrentModuleID:1];
return;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: