Joey
Joey

Reputation: 41

didReceiveRemoteNotification not called on background (Firebase, Postman, iOS)

Problem: `didReceiveRemoteNotification` is not called.

I do get notifications when my app is in background. (real device).

I just want to have didReceiveRemoteNotification called whenever notification arrives in background and no user interaction has been made (no tapping).
(My device is iOS 16.3 and Xcode is 14.1)

What I did

I have a Firebase server and I sent a push notification from Postman.

My header

enter image description here I added apns-push-type, apns-priority, apns-topic (Apple Background push doc)

My Body

{
    "aps" : {
      "content-available" : 1
      },
    "to":"my fcm token",
    "notification" : {
        "title" : "Alarm",
        "body" : "Testing"
        }
}

Other settings

I did FirebaseApp.configure(), Messaging.messaging().delegate = self, UIApplication.shared.registerForRemoteNotifications(), Messaging.messaging().apnsToken = deviceToken.
I also added Push Notifications and Background Modes (Remote notifications, Background fetch)

Upvotes: 2

Views: 1029

Answers (2)

Mykyta Khlamov
Mykyta Khlamov

Reputation: 41

For iOS 16.7 - just simple restart device fix this problem for me.

For iOS 18.1 - I had Background App Refresh disabled on my phone.

After I enabled it in Settings -> General -> Background App Refresh - everything worked fine

Upvotes: 0

VinodA
VinodA

Reputation: 111

Assuming you are using the

application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

Did you try changing the content-available to true or "true" instead of using 1? Refer:didReceiveRemoteNotification not called Swift

Upvotes: 1

Related Questions