我试图从UIApplicationDelegate获取launchOptions的值
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
如果launchOptions是NSDictionary,我可能可以通过
检索值
launchOptions[launchOptions.UIApplicationLaunchOptionsRemoteNotificationKey]
但对象是[NSObject: AnyObject]
。如何检索此类型的值?
答案 0 :(得分:1)
您的变体不安全,请更好地使用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
}
答案 1 :(得分:0)
斯威夫特充满了尝试和调整
这是我自己的答案。
let notifPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey as String!] as? NSDictionary