启动响应特定的viewController到远程推送通知 [英] Launching a specific viewController in response to a remote push notification

查看:130
本文介绍了启动响应特定的viewController到远程推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个应用程序是谁的故事板流像下面的图片:

I'm creating an app who's storyboard flows like the image below:

当用户从Sysalert视图控制器,他们被带进消息列表视图控制器在这里我做一个NSURLConnection的一些JSON装载到表中记录英寸当用户在表中水龙头一排,它们进入邮件详细信息,这显示了该消息的详细信息。

When a user logs in from "Sysalert View Controller" they are brought into "Message List View Controller" where I do an NSURLConnection to load some JSON into the table. When a user taps a row in the table, they are brought into "Message Details" which shows more detailed information for that message.

当用户从一个推送通知在发布之前启动应用程序,无论应用程序的状态,我想该应用从我的服务器加载邮件列表的数据,然后告诉他们这只是被推消息到设备

When a user launches the app from a push notification, regardless of the state of the app prior to launching, I want the app to load the "Message List" data from my server and then show them the message that's just been pushed to the device.

我知道我需要使用 didFinishLaunchingWithOptions 来告诉应用程序来作出反应,推送通知,但我怎么设置视图层次结构,使邮件列表视图控制器装载其数据,然后按下消息详细信息视图控制器压入堆栈,相应的消息?

I know I need to use didFinishLaunchingWithOptions to tell the app to react to the push notification but how do I setup the view hierarchy so that the "Message List" view controller loads its data and then pushes the "Message Details" view controller onto the stack for the appropriate message?

从本质上讲这种模仿的消息或邮件应用程序的行为。凡开口,通知带您到该消息视图控制器,但你仍然可以,如果你已经从最初的viewController又将推出应用程序,并通过遍历该viewControllers层次结构中的回迁。

Essentially this kind of mimics the behaviour of the Messages or Mail apps. Where opening with a notification brings you to a view controller for that message but you are still able to move back in the hierarchy as if you had launched the app from the initial viewController and traversed through the viewControllers in turn.

推荐答案

这是可能做到你的描述,但我不会推荐它。

It's possible to do what you describe, but I would not recommend it.

弗里斯特,将与您在故事板所需的视图断开的视图控制器,给视图控制器的标识符,像我的推送通知视图

Frist, place a disconnected view controller with the view that you want in the storyboard, give the view controller an identifier, something like "My Push Notification View"

didFinishLaunchingWithOptions:,你可以从应用程序委托的RootViewController的。此控制器将导航控制器。使用导航控制器,你可以在堆栈顶部推新视图控制器。要创建新的视图控制器,您实例化标识符我的推送通知视图视图控制器。

In didFinishLaunchingWithOptions:, You can get to the rootViewController from the app delegate. This controller will be the navigation controller. Using navigation controller, you can push a new view controller on top of the stack. To create the new view controller, you instantiate the view controller with the identifier "My Push Notification View".

UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
UIViewController *notificationController = [navController.storyboard instantiateViewControllerWithIdentifier:@"My Push Notification View"];

[navController pushViewController:notificationController animated:YES];

我想你会想使用类似 - presentViewController:动画:完成:来显示一个模式视图,而不是中断导航堆栈

I think you will want to use something like -presentViewController:animated:completion: to show a modal view instead of interrupting the navigation stack.

UIViewController *rootController = (UIViewController *)self.window.rootViewController;
UIViewController *notificationController = [rootController.storyboard instantiateViewControllerWithIdentifier:@"My Push Notification View"];

[rootController presentViewController:notificationController animated:YES completion:NULL];

这篇关于启动响应特定的viewController到远程推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆