iosswiftapple-push-notificationsfirebase-cloud-messagingremote-notifications

didReceiveRemoteNotification function doesn't called with FCM notification server


I'm using FCM server for remote notifications, it worked perfectly with sending and receiving notifications.

My problem is when the device is in the background, this function func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) doesn't called.

Solutions that I've tried:

is called when user tapped on the notification. Otherwise, it's not triggered.

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        
        print("userInfo: \(userInfo)")
      completionHandler(.newData);
  
    }


Solution

  • If you are testing with Postman then try changing "content-available": true to "content_available" : true. content-available will send notification but it doesn't call didReceiveRemoteNotification.