问题
My app allows users to send a message to their friends. They then get a push notification. How can I get the view controller with the incoming messages to be opened when the app is opened via the notification?
回答1:
To do that you will need to override app delegate didFinishLaunchingWithOptions function and check if launchOptions contains any notification key:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let options = launchOptions {
if let notification = options[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] {
//notification found mean that you app is opened from notification
}
}
return true
}
来源:https://stackoverflow.com/questions/28650468/open-view-controller-when-remote-notification-pressed