iOS Notification Service Extension not getting called

See original GitHub issue

Here’s the payload I’m sending from the Firebase Admin SDK (Python)

messaging.Message(
        notification=messaging.Notification(
            body=data_message['body'],
            title=data_message['title'],
        ),
        apns=messaging.APNSConfig(
            payload=messaging.APNSPayload(aps=messaging.Aps(mutable_content=1, content_available=1, sound= "ting.wav"),
              notifee_options={
                'ios':  {
                    'critical': True,
                    'sound': "ting.wav",
                    'criticalVolume': 0.2,
                    'categoryId': "channelHigh",
                },
                'data': data_message
            }
            ),
        ),
        token=registration_token[args.device],
    )

Here’s my NotificationService.m (To debug, I’ve tried to modify the title of bestAttemptContent before sending it to the NotifeeExtensionHelper)

#import "NotificationService.h"
#import "NotifeeExtensionHelper.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
  
  self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [SE]", self.bestAttemptContent.title];
    
  [NotifeeExtensionHelper populateNotificationContent:request
                                  withContent: self.bestAttemptContent
                                   withContentHandler:contentHandler];
}

- (void)serviceExtensionTimeWillExpire {used.
    self.contentHandler(self.bestAttemptContent);
}

@end

In foreground, notification is handled by RNFirebase’s onMessage() function. However, in the background or in quit state it just delivers the notification as-is, with no modifications. It doesn’t even change the title, which leads me to believe that the NSE isn’t getting called at all. Moreover, the setBackgroundMessageHandler isn’t taking effect either.

The only relevant logs I get from Xcode are:

[RNFBMessagingModule signalBackgroundMessageHandlerSet] [Line 95] signalBackgroundMessageHandlerSet called
[RNFBMessagingAppDelegate signalBackgroundMessageHandlerSet] [Line 74] signalBackgroundMessageHandlerSet sharedInstance.backgroundMessageHandlerSet was NO

but I’m very clearly setting the backgroundMessageHandler in my entry-level index.js:

import messaging from "@react-native-firebase/messaging";
import notificationHandler from './notificationHandler'

messaging().onMessage(notificationHandler);
messaging().setBackgroundMessageHandler(notificationHandler);

Any leads on what could be wrong?

Edit: I upgraded from 4.0.0 to 4.1.0 and RNFirebase from 13 to 14, but background notifications didn’t work previously either.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikehardycommented, May 19, 2022

I think there is an edit link on each docs page maybe this could be a note on the extension doc, as a PR?

1reaction
mfbx9da4commented, Apr 5, 2022

In my case the actual notification service extension (NSE) was not firing because of a mismatch of ios targets between the main app and NSE.

My basic issue was that the target iOS version of the newly created extension was higher than the iOS version on the test device. The target iOS version of the extension does not depend on the target iOS version of the app. Project -> Targets -> your_extension -> General (tab) -> Deployment Info

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notification Service Extension Not working - Apple Developer
Hi Team, I was trying to add NSE to my Project to show Rich messaging. Creation of the NSE target to the project...
Read more >
iOS 10 don't call Notification Service Extension - Stack Overflow
Run service extension as the Target instead of the app. · Make sure the deployment target of the service extension is less than...
Read more >
Notification Service Extension Not working - Coding
Notification Service Extension Not working · 1. Check Your Target. You have to run your project with the app as a target for...
Read more >
Notification Service Extension is not calling in ionic capacitor ...
We are trying to integrate Rich Push Notification in ionic capacitor project. As per instructions, we created/added notification service ...
Read more >
Adding a Notification Service Extension
You must have installed WonderPush in your Xcode project already. If you've followed the iOS Quickstart guide, you should be all set and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found