1

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.

Sagar Snehi
  • 398
  • 3
  • 13
  • It is not possible to get the notification data if you do the above. http://stackoverflow.com/questions/11290661/how-to-catch-all-ios-push-notifications-with-different-user-actions-including-ta – Sachin Vas Feb 16 '17 at 06:31
  • but previously i was getting now it's coming nil(Launchoption) when I am opening app using app icon tap – Sagar Snehi Feb 16 '17 at 06:35

0 Answers0