从推送通知中打开应用程序时打开特定的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类的“didReceiveRemoteNotification”方法中添加下面的代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){ NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData) }