简体   繁体   English

弹出本地通知后打开特定的viewcontroller

[英]Opening a specific viewcontroller after popping local notification

I have a tabbarcontroller, in one tab it has a navigationcontroller with tableview controller.And there are different kinds of test-daily,weekly ans so on. 我有一个tabbarcontroller,在一个选项卡中它有一个带有tableview控制器的navigationcontroller。并且有不同类型的每日测试,每周等等。 I want to make a daily localnotification,so when user touches it,my app loads,tabbar contrlorer selects that one navcon(i know how to do that) and then it selects a specific row in the table-how can i do that? 我想进行每日本地通知,所以当用户触摸它时,我的应用程序加载,tabbar contrlorer选择一个navcon(我知道该怎么做),然后它选择表中的特定行 - 我该怎么做? Thank you! 谢谢!

First of all, you have to supply a userInfo property with your UILocalNotification (for the application to know which notification has been triggered later on) 首先,您必须使用UILocalNotification提供userInfo属性(以便应用程序知道以后触发了哪个通知)

With the help of userInfo , you can push the right UIViewController onto the viewController-stack. userInfo的帮助下,您可以将正确的UIViewController推送到viewController-stack。

To respond to opening the app with a shown notification, you have to implement the following method: 要通过显示的通知响应打开应用程序,您必须实现以下方法:

– application:didReceiveLocalNotification: - application:didReceiveLocalNotification:

Just note the following: 请注意以下几点:

If you implement application:didFinishLaunchingWithOptions: to handle an incoming push notification that causes the launch of the application, this method is not invoked for that push notification. 如果您实现application:didFinishLaunchingWithOptions:来处理导致应用程序启动的传入推送通知,则不会为该推送通知调用此方法。

Yes you can. 是的你可以。 The app delegate will be passed the local notification in the application:didFinishLaunchingWithOptions: method. 应用程序委托将在应用程序中传递本地通知application:didFinishLaunchingWithOptions:方法。 The userInfo dictionary will contain the notification in the key UIApplicationLaunchOptionsRemoteNotificationKey . userInfo字典将在密钥UIApplicationLaunchOptionsRemoteNotificationKey包含通知。 Note that the application can be launched already but be inactive, and then when the user enter the application the application:didFinishLaunchingWithOptions: method will not be called. 请注意,应用程序可以已启动但处于非活动状态,然后当用户进入应用程序时,将不会调用application:didFinishLaunchingWithOptions:方法。 To see the notification anyway, use the application:didReceiveLocalNotification: app delegate method instead. 要查看通知,请使用application:didReceiveLocalNotification: app delegate方法。

When you have this working, it's a simple matter of navigating to the right view by selecting the right tab, selecting the cell in the table view etc, which should be straight forward. 当你有这个工作时,通过选择正确的选项卡,在表格视图中选择单元格等,导航到正确的视图是一件简单的事情,这应该是直截了当的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM