繁体   English   中英

从应用程序的launchOptions获取值(…launchOptions:[NSObject:AnyObject]?)

[英]get the value from launchOptions at application(… launchOptions: [NSObject: AnyObject]?)

我正在尝试从UIApplicationDelegate获取launchOptions的值

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

如果launchOptions是NSDictionary,我可能可以通过以下方式检索值

launchOptions[launchOptions.UIApplicationLaunchOptionsRemoteNotificationKey]

但是对象是[NSObject: AnyObject] 如何获取此类型的值?

您的变体不安全,请使用if let语句更好地使用:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    if let options = launchOptions as? [String: AnyObject],
           notifyPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] {
            // do smth with notifyPayload
    }
    return true
}

斯威夫特充满尝试和调整

这是我自己的答案。

  let notifPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey as String!] as? NSDictionary

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM