问题描述
我想做类似 Twitter 应用的事情:当有人给我写信时,我会收到推送通知;如果我在通知上滑动",应用程序会启动,但不是在正常的流中,它会在特定视图中启动,并带有某人写给我的推文!
I want to do something like Twitter app: when someone write me I receive the push notification; if I "slide on the notification" the app starts, but not in the normal stream, it starts in a specific view with the tweet that someone wrote me!
在我的应用程序中,我有一个类似于 RSS 阅读器的东西,当有新消息时,推送通知就会到达.所以,我想打开单一新闻视图",而不是主视图(现在正在发生).
In my app I have something like an RSS reader, and the push notification arrives when there is a new news.So, I want to open the "single news view", and not the main view (that's happening now).
我能做什么?
谢谢
推荐答案
您可以做两件事.
一是检查UIApplicationDelegate
方法的launchOptions
字典
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
查看应用是否是通过用户点击通知启动的.如果是这样,那么在该方法中,您可以将适当的视图控制器推送到堆栈上,就像您通常在应用内使用一样.
to see if the app was launched via a user clicking on a notification. If so, then in that method you can push the appropriate view controller onto the stack, just as you would normally with in-app usage.
如果应用程序已经打开,但在后台,那么同样的理论适用,但使用 UIApplicationDelegate
方法
If the app is already open, but in the background then the same theory applies but instead use the UIApplicationDelegate
method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
参见 此链接 了解有关处理传入通知的信息.
See this link for information on handling incoming notifications.
这篇关于当用户收到推送通知时打开特定的选项卡/视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!