Open view controller when remote notification pressed

一世执手 提交于 2019-12-11 03:07:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!