1

How can I go to a certain view when the app is opened from push notification? I am using storyboards. I have some views that push and some that are modal. I need to go to a certain view from anywhere in the app. This view is pushed by a view that is normally only access from a settings type page that pushes this view.

4

2 回答 2

2

如果您的应用程序在后台运行。在这种情况下。

从方法调用下方的推送通知打开应用程序时。

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

使用 userInfo 您可以设置要推送的视图的方式。假设我不想去依赖 pushNotification 的 firstView 在这种情况下,我将在 APNS 有效负载中添加一个值,例如view:firstView(可能是你的类名)并使用来自userinfoNSDictionary)的这个值你可以导航或推送到特定的观点。在这种情况下,您的 APNS 有效负载将是这样的

{"aps":{"alert":"Your message","sound":"value","badge":1},"ViewName":"value"}

于 2013-07-12T10:14:53.730 回答
2

您可以在 Notification Payload 中添加额外的参数。在推送通知编程指南部分通知有效负载它指出

提供者可以在 Apple 保留的 aps 命名空间之外指定自定义有效负载值。自定义值必须使用 JSON 结构化和原始类型:字典(对象)、数组、字符串、数字和布尔值。您不应将客户信息作为自定义有效负载数据包含在内。相反,将其用于设置上下文(用于用户界面)或内部指标等目的。例如,自定义有效负载值可能是供即时消息客户端应用程序使用的对话标识符,或者是标识提供者何时发送通知的时间戳。与警报消息相关的任何操作都不应具有破坏性——例如,删除设备上的数据。

您可以在 AppDelegate 函数application:willFinishLaunchingWithOptions 中读取此参数:

在那里您可以重新创建 UINavigationController 实例。

于 2013-07-12T10:08:36.257 回答