con*_*fin 24 uiviewcontroller push-notification apple-push-notifications ios
我正在创建一个应用程序,其故事板如下图所示:

当用户从"Sysalert View Controller"登录时,它们被带入"消息列表视图控制器",我在其中执行NSURLConnection以将一些JSON加载到表中.当用户点击表中的一行时,它们将被带入"消息详细信息",其中显示该消息的更多详细信息.
当用户从推送通知启动应用程序时,无论启动之前应用程序的状态如何,我都希望应用程序从我的服务器加载"消息列表"数据,然后向他们显示刚被推送到设备的消息.
我知道我需要用来didFinishLaunchingWithOptions告诉应用程序对推送通知做出反应但是如何设置视图层次结构以便"消息列表"视图控制器加载其数据然后将"消息详细信息"视图控制器推送到堆栈上适当的消息?
基本上这种模仿消息或邮件应用程序的行为.如果打开通知会将您带到该消息的视图控制器,但您仍然可以在层次结构中向后移动,就像您从初始viewController启动应用程序并依次遍历viewControllers一样.
你可以做你所描述的,但我不推荐它.
Frist,将断开连接的视图控制器与故事板中所需的视图放在一起,为视图控制器提供标识符,例如"我的推送通知视图"
在didFinishLaunchingWithOptions:,您可以从应用程序委托到达rootViewController.该控制器将是导航控制器.使用导航控制器,您可以在堆栈顶部推送新的视图控制器.要创建新的视图控制器,请使用标识符"My Push Notification View"实例化视图控制器.
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
UIViewController *notificationController = [navController.storyboard instantiateViewControllerWithIdentifier:@"My Push Notification View"];
[navController pushViewController:notificationController animated:YES];
Run Code Online (Sandbox Code Playgroud)
我想你会想要使用类似于-presentViewController:animated:completion:显示模态视图而不是中断导航堆栈的东西.
UIViewController *rootController = (UIViewController *)self.window.rootViewController;
UIViewController *notificationController = [rootController.storyboard instantiateViewControllerWithIdentifier:@"My Push Notification View"];
[rootController presentViewController:notificationController animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13720 次 |
| 最近记录: |