按下远程通知时打开视图控制器

时间:2015-02-21 19:43:49

标签: swift push-notification viewcontroller

我的应用允许用户向朋友发送消息。然后他们会收到推送通知。当通过通知打开应用程序时,如何通过打开传入消息来获取视图控制器?

1 个答案:

答案 0 :(得分:3)

为此,您需要覆盖app delegate didFinishLaunchingWithOptions函数并检查launchOptions是否包含任何通知密钥:

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
}