Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[iOS] issue with NSE and use_frameworks! #130

Closed
bperlman opened this issue Aug 11, 2021 · 17 comments
Closed

[iOS] issue with NSE and use_frameworks! #130

bperlman opened this issue Aug 11, 2021 · 17 comments

Comments

@bperlman
Copy link

Following the directions exactly from the documentation, when providing the notifee_options key as below, I get two notifications displayed when the app is in a killed state. One with just the plain notification, and one with the image attached. I only get the double notification on iOS as well.

{
    notification: {
      title: 'A notification title!',
      body: 'A notification body',
    },
    apns: {
        payload: {
            aps: {
                'content-available': 1, // Important, to receive `onMessage` event in the foreground when message is incoming
                'mutable-content': 1, // Important, without this the extension won't fire
            },
            notifee_options: {
                image: 'https://placeimg.com/640/480/any', // URL to pointing to a remote image
           
            },
        },
    },
    ...
};

This doesn't happen when the app is in the foreground or background (presumably since those are not handled by the NotifeeNotificationService).

I have no other Notification Service Extensions in the app.

Do you have any ideas of what could be causing this? At a bit of a loss.

@bperlman
Copy link
Author

bperlman commented Aug 12, 2021

So update on this - I added some code to adjust titles on notifications so I could figure out if they were being displayed via the Notification Service, Background Handler, or Foreground Handler in the app.

The plain text notification is from the NotifeeNotificationService. I added a line to adjust the title before the NotifeeExtensionHelper takes it from there. The title gets adjusted, but none of the notifee_options from the actual notification get applied. They don't get applied if the title adjustment line is removed either.

Relevant lines from NotificationService.m

- (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:self.bestAttemptContent withContentHandler:contentHandler];
    
}

The additional notification with the image is coming from the firebase setBackgroundMessageHandler which I have executing notifee.displayNotification which is unexpected since the app is in a fully closed state.

I am guessing I have misunderstood something here - my assumptions/problems I am running into are as follows. Does anything here point out where I may be going wrong or have misunderstood a concept?

  1. I was under the (maybe mis-?) understanding that the firebase setBackgroundMessageHandler function would only work when the app is in the background, i.e. not fully killed. This mostly seems to be the case as it doesn't produce a notification when the phone is restarted (only notification comes from the service extension) but it seems to continue to display a notification after the app is launched at least once and fully quit. I understood that the firebase setBackroundMessageHandler wouldn't work for situations when the app is fully quit, hence the 'Remote Notification Support' section of the iOS docs.

Update: it seems that after several minutes, only the Service Extension notification happens until the app is re-launched again..so its like the firebase handler is still active for several minutes after the app is quit? So that duplicate notification only happens for a little bit after the app is quit it seems...which...is fun.

  1. I understood that the NotifeeNotificationService wouldn't do anything in cases where the app's js is running in some way, i.e. when it's fully open (seems to be the case) and also when it's inactive but still open (doesn't seem to be the case). But it seems like there's a case here where both the NotifeeNotificationService and firebase setBackgroundMessageHandler are active? (This appears to be the case when the app is in the background, and in the recently quit state I mention above.)

  2. I was using data-only notifications, but added the notification key to the notification payload in order to trigger the NotifeeNotificationService when the app is fully quit. Our backend doesn't know when the app is active or not so it's not like that can reasonably be adjusted dynamically to solve this issue. And the setBackgroundMessageHandler doesn't seem reliable enough to always rely on data-only notifications for non-active app states. Is there a best practice here that I'm missing?

  3. I am not sure why the NotifeeNotificationService extension is not applying the notifee_options, i.e. image.

  4. The only other thing is that our main target uses use_frameworks! in the Podfile so I had to add that on the NotifeeNotificationService target as well in order for pod install to be successful. Could that be causing a problem with the notification service extension?

@helenaford
Copy link
Member

  1. setBackgroundMessageHandler is both background and quit states (reference: https://rnfirebase.io/messaging/usage#message-handlers)
    1a. the setBackgroundMessageHandler isn't reliable and not always called which you are correct in the reason why we added this support in Notifee
  2. yes, the setBackgroundMessageHandler will fire whenever there's an incoming message (notification/data), if you are sending a notification-type message, you shouldn't call displayNotification (if that answers your question).
  3. best practice is not to rely on data-only messages to display notifications on iOS
  4. the service extension should be triggered - if everything else is covered, I'm happy to debug this with you. I appreciate the insights/feedback, we're always looking to improve the docs and make things easier to implement.
  5. interesting, do you have swift files in your project? I will double-check this. There's an open thread on flutterfire describing something very similar where the image doesn't show due to use_frameworks! 🐛 [firebase_messaging] Notification Images setup problem iOS firebase/flutterfire#4133

@helenaford helenaford changed the title [iOS] Help - Duplicate Notifcation with NotifeeNotificationService only when notifee_options provided [iOS] Help - Data-only and notification messages with NSE and setBackgroundMessageHandler Aug 15, 2021
@bperlman
Copy link
Author

1 - 3 - Thank you! I wrapped my head around that a little more over the last few days (I should have updated this in the meantime) and changed the function invoked by setBackgroundMessageHandler so that it doesn't call displayNotification if a notification key is present so that seems like that's right - so now it's just a matter of getting the NSE working properly.

4: Thats where I am at now, the service extension appears to be triggered but does not appear to be applying the notifee 'features' to the message before it gets displayed. I also added a different subject to the fallback aspect as well to rule that out as a possible issue as well, which, is not the case. So, yes, any help getting that working would be great, I am really not sure where to start with it since everything appears to be set up, except if 5 is what is causing the issue.

5: That could be the case, so far I have only tried with the image option of notifee_options so I'll fiddle with something else as well. Admittedly I'm not strong on the native side, but yes there's swift so we can't remove the use_frameworks! bit... So, I appreciate you guys looking into that aspect and whether or not that causes an issue for the NSE.

@bperlman
Copy link
Author

So where I am at now, I need help getting the NSE to actually make notifee post the message, as it's requiring a workaround to handle initial notifications since the getInitialNotification method isn't going to work since the messages are being posted by firebase.

I am able to make things work by using the firebase onNotificationOpenedApp method for now, but basically, the NSE is doing nothing even though it's definitely firing (I can adjust the notification title so I know it's firing) - possibly an issue around use_frameworks! - so Ideally would appreciate you guys making updates there either to the package or documentation given that this is a licenced package.

Thank you!

@helenaford
Copy link
Member

@bperlman can you share what's in the native logs, filtering by Notifee? If you have your app running, and the title is changing from the NSE, it could be an issue with the image itself - there should be some logs in the console. Another thing to try is testing with a project (an example app) that doesn't require use_frameworks! and see if that works?

@bperlman
Copy link
Author

bperlman commented Aug 23, 2021

Is there somewhere I can send that log output to you so it's not in a public issue? (Easier than having to scrub it all).

The image works fine when the app is in the foreground and Notifee is handling the display of the notification on the JS side, and the image shows up fine on Android, so the image being broken seems unlikely.

Unfortunately, I don't have time to create a blank project to test the use_frameworks! bit at the moment. Respectfully - I think given that this is a paid/licensed package, that's the sort of testing and trial/error that is likely more appropriately done on your team's side if at all possible as that's something that several people will likely run into.

Thank you :)

@mikehardy
Copy link
Collaborator

@bperlman you can try our Discord server https://discord.gg/pSGPWHgd then I think you may be able to DM either @helenaford or @mikehardy there?

@bperlman
Copy link
Author

Ok, thanks @mikehardy I'll give that a try!

@bperlman
Copy link
Author

@helenaford I've sent you a request on Discord for whenever you have time, can continue there. Thanks again for your help!

@Salakar Salakar transferred this issue from invertase/react-native-notifee Sep 24, 2021
@brandonpearcy
Copy link

@bperlman Was there any resolution here? I'm running into the exact same issue. Aside: I really appreciate your thorough notes!

@bperlman
Copy link
Author

hey @brandonpearcy - no there was no resolution, @helenaford and I chatted a bit but our schedules didn't really line up - I am also not super well versed on the native side so my ability to troubleshoot there is somewhat limited...it does appear that this may be a problem that requires an update to notifee though as far as I can tell thus far...not sure if @helenaford has any updates...

@helenaford
Copy link
Member

Hey all, there's an alpha release that's just been published that will eliminate the need for an NSE if you don't need to modify any content but just use notifee to manage the following events - Press, Action Press and dismiss. More info here

@bperlman
Copy link
Author

Thanks for the update! The part where I am still stuck is the NSE doesn't seem to modify to add images, etc, while use_frameworks! is enabled. Is there anything in the works re: that?

@helenaford
Copy link
Member

ah ok, gotcha! sorry, yeah you would still need the NSE 🤔 mmmm... Would you be able to clone our example app and push up a repro?

@bperlman
Copy link
Author

I, unfortunately, don't have the bandwidth to do that right now. But it seems that others are having the same issue. Since this is a paid license I would respectfully ask that this digging be done on the invertase side if at all possible. Since I dont have time to dedicate to creating that reproduction right now, I've kind of been ok with living with it for now. Perhaps others that are having the same trouble may be able to jump in if they have some more time available

@helenaford
Copy link
Member

@bperlman totally understand where you are coming from regarding bandwidth

Quick question: have you tried this solution? If not might be worth a shot... there's a thread where people have said that worked for them

@helenaford helenaford changed the title [iOS] Help - Data-only and notification messages with NSE and setBackgroundMessageHandler [iOS] issue with NSE and use_frameworks! Nov 19, 2021
@helenaford helenaford added the ios label Nov 19, 2021
@github-actions
Copy link

github-actions bot commented Dec 6, 2022

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants