Detect if application: didReceiveRemoteNotification: fetchCompletionHandler: was called by tapping on a notification in Notification Center

前端 未结 8 1819
北荒
北荒 2021-01-30 16:38
application: didReceiveRemoteNotification: fetchCompletionHandler:

is different from

application: didReceiveRemoteNotification:
         


        
8条回答
  •  春和景丽
    2021-01-30 17:18

    For Swift: In application(_:didFinishLaunchingWithOptions:) parse the application options. If they exist, you know the app was launched from them tapping.

      if let remoteNotif = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [String: Any] {
            print("Remote notfi is \(remoteNotif)")
            if let notification = remoteNotif["aps"] as? [AnyHashable : Any] {
            /// - parse notification
          }
      }
    

    Otherwise, you can handle the tap in, and you know that the app is open/background/inactiveapplication(_:didReceiveRemoteNotification:fetchCompletionHandler:)

提交回复
热议问题