问题
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:
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)
}
来源:https://stackoverflow.com/questions/34856605/open-specific-viewcontroller-when-opening-app-from-push-notification