从推送通知打开应用程序时打开特定 viewcontroller
Open specific viewcontroller when opening app from push notification
如标题所示:当用户通过滑动推送通知启动应用程序时,如何打开特定的 viewcontroller?
谢谢!
执行以下操作,
在您的应用程序主视图控制器 "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 class 的 "didReceiveRemoteNotification" 方法中添加以下代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData)
}
如标题所示:当用户通过滑动推送通知启动应用程序时,如何打开特定的 viewcontroller?
谢谢!
执行以下操作,
在您的应用程序主视图控制器 "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 class 的 "didReceiveRemoteNotification" 方法中添加以下代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData)
}