2016-09-20 75 views
1

我在swift 2.2中正常工作,但是當我轉換爲swift 3.0時會出錯。UIApplicationLaunch通過remoteNotification swift 3不能正常工作

//If app open by notification 
if launchOptions != nil 
{ 
    NSLog("launch------ %@", launchOptions!) 

    let userInfo = launchOptions!(UIApplicationLaunchOptionsKey.remoteNotification) as NSDictionary 
    if userInfo != nil 
    { 
     self.application(UIApplication.shared, didReceiveRemoteNotification: (userInfo)! as! [NSObject : AnyObject]) 
    } 
} 

錯誤等

無法調用非功能型的值 '[NSObject的:任何]'

預先感謝。

回答

1

最後我固定: -

if launchOptions != nil 
{ 
    NSLog("launch------ %@", launchOptions!) 
    let userInfo = launchOptions![UIApplicationLaunchOptionsKey.remoteNotification] as! NSDictionary 
    if userInfo != nil 
    { 
     self.application(UIApplication.shared, didReceiveRemoteNotification:(userInfo) as! [AnyHashable : Any] as! [String : AnyObject]) 
    } 
} 
+0

我做的時候我用這個得到一個錯誤,你使用的是什麼Xcode版本?我正在使用8測試版3,並且似乎給出了一個錯誤:對成員'下標'的歧義引用 – TheeBen

+0

您可以在這裏向我展示代碼。 –

1

我對雨燕3.解決方案,我必須使用一些投以獲取值:

let key : AnyObject = UIApplicationLaunchOptionsKey.remoteNotification as AnyObject 
    if let remoteNotification = launchOptions![key as! NSObject] as? [NSObject : AnyObject]{ 
     self.application(application: application, didReceiveRemoteNotification: remoteNotification) 
    }