从推送通知打开应用程序时打开特定的viewcontroller

时间:2016-01-18 14:03:05

标签: ios swift notifications push

正如标题所暗示的:当用户通过滑动推送通知启动应用时,如何打开特定的视图控制器?

谢谢!

1 个答案:

答案 0 :(得分:3)

执行以下操作,

在您的应用主视图控制器" 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)
    }
}

并在" didReceiveRemoteNotification"中添加以下代码App的appdelegate类的方法

 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){

     NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData)
}