[英]How to get custom Push Notification value from launchOptions with swift?
[英]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.