I am getting notification from FCM with data. When app is in foreground everything is working fine.When I closed(killed) the app and got notification, by tap on notification than also I am getting data. My problem is when I closed the app and get notification, Instead of tapping notification I am opening the app directly from app icon. I am not getting any data in launchOptions in didFinishLaunchingWithOptions function.
Here is my code to take data when app is launching from app Icon:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
self.handleNotification(remoteNotification as [NSObject : AnyObject])
}
FIRApp.configure()
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
// Add observer for InstanceID token refresh callback.
NSNotificationCenter
.defaultCenter()
.addObserver(self, selector: #selector(AppDelegate.tokenRefreshNotificaiton),
name: kFIRInstanceIDTokenRefreshNotification, object: nil)
return true
}
I am getting launchOptions
always as nil, although there is notification having data.
I am using swift2
and Xcode7
. Please suggest me on this why my launchOptions
is coming nil
?
I searched in google There its saying that if I will open app using app icon launchOption will come nil only.