Mitul Marsoniya
Mitul Marsoniya

Reputation: 5299

UIApplicationLaunch by remoteNotification swift 3 not working

I have working properly in swift 2.2 but when i convert to swift 3.0 then get error.

//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])
     }
}

Error like

Cannot call value of non-function type '[NSObject : Any]'

Thanks in advance.

Upvotes: 1

Views: 2452

Answers (2)

Kevin ABRIOUX
Kevin ABRIOUX

Reputation: 17695

My solution for Swift 3. I have to use some cast in order to get the value :

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

Upvotes: 1

Mitul Marsoniya
Mitul Marsoniya

Reputation: 5299

Finally i fixed :-

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])
     }
}

Upvotes: 1

Related Questions