Reputation: 5299
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
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
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