当从应用程序图标直接打开应用程序时,有效负载数据(推送通知FCM)为零,而不是来自通知点击

时间:2017-02-07 12:57:06

标签: ios swift firebase notifications firebase-cloud-messaging

我收到来自FCM的数据通知。当应用程序处于前台时,一切正常。当我关闭(杀死)应用程序并获得通知时,通过点击通知而不是我获取数据。我的问题是当我关闭应用程序并收到通知时,我没有点击通知,而是直接从应用程序图标打开应用程序。我没有在didFinishLaunchingWithOptions函数的launchOptions中获取任何数据。

以下是我的应用程序从应用程序图标启动时获取数据的代码:

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
}

我的launchOptions总是为零,尽管有通知有数据。

我正在使用swift2Xcode7。请建议我为什么launchOptions即将到来nil? 我在google搜索它说它如果我将使用app图标打开应用程序launchOption将仅为零。

0 个答案:

没有答案
相关问题