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:
This function:
userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
is called when user tapped on the notification. Otherwise, it's not triggered.
Adding "content-available": true, "priority": "high"
to the payload. Also, I tried this value "content-available": 1
.
This is my function code:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("userInfo: \(userInfo)")
completionHandler(.newData);
}
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
.