didReceiveRemoteNotification not called in iOS 13.3 when app is in background

11,663

Solution 1

Have you set

"content-available": 1

in you backend APS payload?

Also need to make sure you have enabled background mode in your iOS App's info.plist file

<key>UIBackgroundModes</key>
<array>
    <string>processing</string>
    <string>remote-notification</string>
</array>

Solution 2

This delegate method : -

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{

is getting invoked when we click on notification for iOS 13 and app is in background.

Solution 3

I spend a support ticket to get an answer to this problem.

It turns out that the documentation is not 100% "valid" for iOS 13 on this topic. The device decides whether to wake up or not. Although the documentation states a little different.

Apple's preferred way of implementation as a notification extension. After that, you have to adapt the payload to include "mutable-content".

I asked the support afterward if I should file a radar and they replied with "yes".

Solution 4

Need activated "BackGround fetch" go to File Project - signIn capabilities - BackgroundModes - and check Background fetch and Remote notifications as well

remember in didFinishAlunchWithOptions

    Messaging.messaging().delegate = self
    UNUserNotificationCenter.current().delegate = self

with that I have a response in method - didReceive response - in background but only if tap the notification.

I found this info... but i dont know if is real

"If this is a new system behavior from iOS, then it's unlikely that FCM will be able to provide a workaround. A few things to note:

Apple's docs mention that silent notifications will be throttled by the system to conserve power. In the past, we've seen that testing silent notifications with your device plugged in to a power source will reduce throttling. In older iOS versions, Apple's docs have mentioned that force-quitting an application will prevent wakeups from silent notifications entirely. I'm not sure if this is still the case."

I Still looking around for the notifications in background for update badge icon in the app, at the momen I receive the notification.

Share:
11,663
MartinW1985
Author by

MartinW1985

Updated on June 14, 2022

Comments

  • MartinW1985
    MartinW1985 about 2 years

    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:

    [[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.

    What am I missing here for iOS 13?