按下远程通知时打开视图控制器 [英] Open view controller when remote notification pressed

查看:72
本文介绍了按下远程通知时打开视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

为此,您需要覆盖应用程序委托 didFinishLaunchingWithOptions 函数并检查 launchOptions 是否包含任何通知键:

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
}

这篇关于按下远程通知时打开视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆