2016-09-20 3 views
1

스위프트 2.2에서 제대로 작동하지만 swift 3.0으로 변환하면 오류가 발생합니다. 사전에UIApplicationLaunch by 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을 사용하고 있으며 오류를 줄 것 같습니다 : 회원의 'subscript'에 대한 모호한 참조 – 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) 
    } 
관련 문제