【发布时间】:2016-04-23 17:38:13
【问题描述】:
顾名思义:当用户通过滑动推送通知启动应用程序时,如何打开特定的视图控制器?
谢谢!
【问题讨论】:
-
这个问题实际上不应该被标记为重复,因为它被标记为 swift 并且链接的问题是 Objective-C。
标签: ios swift notifications push
顾名思义:当用户通过滑动推送通知启动应用程序时,如何打开特定的视图控制器?
谢谢!
【问题讨论】:
标签: ios swift notifications push
执行以下操作,
在您的应用程序主视图控制器“viewDidLoad”方法中添加一个观察者,
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "SomeNotificationAct:",
name: "SomeNotification",
object: nil)
并且还要添加一个方法
func SomeNotificationAct(notification: NSNotification){
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier("NotificationView", sender: self)
}
}
并在您应用的 Appdelegate 类的“didReceiveRemoteNotification”方法中添加以下代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData)
}
【讨论】: