Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

iOS Notification Service Extension not getting called #327

Closed
zenshayan opened this issue Mar 1, 2022 · 8 comments
Closed

iOS Notification Service Extension not getting called #327

zenshayan opened this issue Mar 1, 2022 · 8 comments
Labels
ios needs-feedback Waiting on response to questions question

Comments

@zenshayan
Copy link

zenshayan commented Mar 1, 2022

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.

@helenaford
Copy link
Member

helenaford commented Mar 1, 2022

Hey, umm it's hard to say. Someone had something similar before (here) and I suggested the following:

_To do a quick debug, leave it the service extension code as

self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];

self.contentHandler(self.bestAttemptContent);
if title isn't changing, you know 100% that your extension isn't being triggered._

This will help determine if the issue is with the setup of the notification service extension or it's something to do with the payload you are sending

@helenaford helenaford added the needs-feedback Waiting on response to questions label Mar 1, 2022
@zenshayan
Copy link
Author

Hey, I've tried that. it still hasn't modified the title. I've even ensured that the NSE is embedded in my main target's "Frameworks, Libs & Embedded Content" section, and included in the build phases. I've even ensured that the signing & provisioning profiles are correct.

Either way, I've "solved" avoided my problem by ditching the NSE altogether and using one of your PRs #236 that allows me to use actions directly.

For anyone else who stumbles upon this, I've also gotten rid of the "notify_options" section and moved it into apns.payload:

apns=messaging.APNSConfig(
            payload=messaging.APNSPayload(aps=messaging.Aps(mutable_content=1, content_available=1, category="channelHigh",  messaging.CriticalSound(
                critical=1,
                name="ting.wav",
                volume=0.2
            ))
            ),
        ),

Thanks @helenaford for the PR & contributions to this project! Any idea on when (if) this PR will be merged?

@ngohuy0972
Copy link

ngohuy0972 commented Apr 4, 2022

Any progress with this issue? In my project, I try to set up a payload followed https://notifee.app/react-native/docs/ios/remote-notification-support but it also can not modify and show notification

@mfbx9da4
Copy link

mfbx9da4 commented 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

@luatvudinh
Copy link

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

Thanks a lot. Saved my days.

@mikehardy
Copy link
Collaborator

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

@helenaford
Copy link
Member

Closing this as there's a solution above of ensuring the versions match of the nse with your project.

Another possible solution as @zenshayan mentions above is to use the @next version of the library which removes the need for the NSE if you do not require using any images.

@jdarshan5
Copy link

jdarshan5 commented Nov 24, 2023

Hi @helenaford, I am also facing the same.

I did follow all the states that are mentioned in Notifee documentation to integrate an NSE from here https://notifee.app/react-native/docs/ios/remote-notification-support.

Some Information that might be useful to debug,

in Podfile have added this lines of code:

$NotifeeExtension = true

target 'NotifeeNotificationService' do
  pod 'RNNotifeeCore', :path => '../node_modules/@notifee/react-native/RNNotifeeCore.podspec'
end

NotificationService.m file:
Screenshot 2023-11-24 at 11 24 33 AM

This is the payload that I am passing in rest api for push notification:

{
    "message": {
        "token": "<FCM_TOKEN>",
        "notification": {
            "title": "Test Title",
            "body": "Test Body"
        },
        "apns": {
            "payload": {
                "aps": {
                    "sound": "default",
                    "mutable-content": 1,
                    "content-available": 1
                },
                "notifee_options": {
                    "image": "https://www.gstatic.com/mobilesdk/160503_mobilesdk/logo/2x/firebase_28dp.png"
                }
            }
        }
    }
}

I did even checked the console logs of my device, which you can see in the screenshot when getting a Push Notification while App being in background and killed (By User Swiping app) state. In both cases the console logs are same.

Screenshot 2023-11-24 at 11 12 05 AM

Now the thing is that I also faced the same issue (Same console logs) while integrating NSE using firebase messaging (using this doc https://rnfirebase.io/messaging/ios-notification-images), and this issue was resolved by applying this changes mentioned at here invertase/react-native-firebase#7360 (comment), where they indicated that changing some order of build phases resolves that issue and it did do the thing but that is not the case with notifee NSE. Can you please help me with this

Here is the build phase for my project:
Screenshot 2023-11-24 at 11 39 58 AM

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
ios needs-feedback Waiting on response to questions question
Projects
None yet
Development

No branches or pull requests

7 participants