Open specific viewcontroller when opening app from

2019-03-22 06:55发布

This question already has an answer here:

As the title implies: how do I open a specific viewcontroller when a user starts the app by swiping on a push notification?

Thanks!

1条回答
我命由我不由天
2楼-- · 2019-03-22 07:42

Do the following,

in your apps main view controller "viewDidLoad" method add an observer,

NSNotificationCenter.defaultCenter().addObserver(self,
        selector: "SomeNotificationAct:",
        name: "SomeNotification",
        object: nil)

And also add a method

func SomeNotificationAct(notification: NSNotification){     
    dispatch_async(dispatch_get_main_queue()) {
     self.performSegueWithIdentifier("NotificationView", sender: self)
    }
}

and add the below code in your "didReceiveRemoteNotification" method of Appdelegate class of your app

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

     NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData)
}
查看更多
登录 后发表回答