didReceiveRemoteNotification not called in iOS 13.3 when app is in background

I am banging my head. I am implementing push notification. Everything is working fine (push is received, badge is updated) but under iOS 13.3 the method application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is not called when the app is in the background. If the app is in the foreground or using an iOS 12 device the method is called. I register for push notification in the following way (yes, it is still Objective C)


[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
  if (granted) {
  dispatch_async(dispatch_get_main_queue(), ^{
  [[UIApplication sharedApplication] registerForRemoteNotifications];
  });
  }
}];


The payload is set to the following:


{"aps": {
  "badge": 10,
  "alert": "test",
  "content-available": 1
}}


I tried adding "Remote notifications" and "Background processing" as app capabilities in all variations (only "Remote notifications"/"Background processing", without any of those capabilities, enabling both) without any change. I set the delegate for the UNUserNotificationCenter but again without success. I set the headers accordingly:


curl -v \
 -H 'apns-priority: 4' \
 -H 'apns-topic: xx.xxxxx.xxxx' \
 -H 'apns-push-type: alert' \
 -H 'Content-Type: application/json; charset=utf-8' \
 -d '{"aps": {"badge": 10,"alert": "test", "content-available":1}}' \
 --http2 \
 --cert pushcert.pem \
 https://api.sandbox.push.apple.com/3/device/1234567890


From the docs it states that this method is called even when the app is in background:


Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background.


I tried with and without background modes (Remote Notification, Background processing, Background fetch) but without success. If I use an iOS 12 device, the method is called.


My goal is to process some of the information in the payload (there might be additional information).

What am I missing here for iOS 13 (13.3 to be exact)?

I'm facing the same issue. Please let me know if you were able to figure it out.

I am also facing the same issue. Does anyone solved this issue. I get call back when app is in the foreground and when user clicks on push notification to

didReceiveRemoteNotification

Please let me know If anyone has solution.

In my case, the solution was: move the super call to the beginning of didFinishLaunchingWithOptions method implementation


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [super application:application didFinishLaunchingWithOptions:launchOptions];
  …
  return YES;
}
Facing the same issue on iOS 14.0.1
I am facing the same issue in 13.3, can you tell me the solution if you have done.
I can't believe this is still not answered.
Can anyone handle silent notifications with firebase on iOS 14 using swift?
Still anyone got solution ?

Any update?

What worked for me in iOS 14 is adding "content-available": "true"

Try explicitly setting "content-available" to 1 (integer) (as noted by many others), leave out the alert key, AND the sound entry to an empty string. That made the difference for me, after a rather exhaustive diagnostic session. I was omitting the sound entry and it never worked. I tried setting a sound file name and it never worked. Setting it to an empty string ( "" ) worked fine when accompanied by content-available and omitting the alert key.

Printing what I receive (as seen below with my various diagnostic print statements) showed: ["sound": , "content-available": 1, "badge": 0]

        guard let aps = userInfo["aps"] as? [String: AnyObject] else {
            print( "Incoming failed" )
            completionHandler(.failed)
            return
        }

        print( aps )
        print( "INCOMING" )

I was struggling with this problem.

However, it disappears after I reboot my device : )

I'm using iOS 15.2

Same for me, it disappears after I reboot my device. iOS 15.3.1

So I was implementing a Background Notification and had the same problem where the "didReceiveRemoteNotification" delegate method was not getting called. Weirdly enough in my case, adding "badge": 0 worked. My sample payload looks like this:

{"aps":{"content-available":1,"apns-priority":5,"apns-push-type":"background","badge":0},"yourCustomKey":"1"}

Make sure you to include these headers:

apns-push-type: background
apns-priority: 5

and this in the payload/body:

{"aps":{"content-available":1}}

There is another scenario that most of the replies are not identifying and the docs are not mentioning either.

In my case, I had my device configured with a special uncommon/unrelated setting.

Go to Settings -> General -> Background App Refresh

You are presented with 3 options:

  1. Off
  2. Wi-Fi
  3. Wi-Fi Cellular Data

!IMPORTANT! There are a viral videos on social network recommending setting this to "Off" or "Wi-Fi" in order to save battery life / data plan. Thats when I set this to "OFF", and didReceiveRemoteNotification was never being called in the background, but strangely enough it was called once I opened the app.

Even if you have it on "Wi-Fi / Cellular Data", if you don't have internet, it wont be called (duhh), but most important, I think the guides should recommend having this small detail covered in case there are users that fall in the "condition" of having this set to "Off" or "Wi-Fi" and being on Cellular network <- this is more common case.

The conditional for this can be retrieved at: UIApplication.shared.backgroundRefreshStatus

https://developer.apple.com/documentation/uikit/uiapplication/1622994-backgroundrefreshstatus

And the funny thing is that it will mess up your logic once the device is in low-power mode, because it will automatically change the status to "Off".

There is nowhere to find that this impacts notifications arriving when app is in background mode, so thats odd. Anyways, hope this helps -roberto

didReceiveRemoteNotification not called in iOS 13.3 when app is in background
 
 
Q