1

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

  • I also tried true and "true" for content-available.
{
    "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)

Joey
  • 31
  • 3

1 Answers1

1

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

VinodA
  • 91
  • 6
  • Thanks for the comment! I just realized that this method is called sometimes. And it worked when `content-available` was true, "true" or 1. It just doesn't work all the times. If I launch the app 20 times, it's gonna work once for the first notification. – Joey Feb 04 '23 at 05:25
  • I figured out that it is called when I the notification is received right before `didEnterBackgroundNotification` is called. Meaning still not called after entering background – Joey Feb 04 '23 at 05:53
  • Did you try the push notification test from firebase something on the lines of https://firebase.google.com/docs/cloud-messaging/ios/first-message I might be working on something around this next and I can investigate a bit more when I do to test. – VinodA Feb 04 '23 at 09:46