我正在尝试从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
}
关于ios - 从应用程序的launchOptions中获取值(…launchOptions:[NSObject:AnyObject]?),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34127052/