-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
🔥 [🐛] isHeadless flag on iOS unreliable #5388
Comments
Is there a place where I can look into this thing and see if I can find the problem? This bug is causing us quite some troubles... |
This is an area of some pain that I've looked into a bit yes. We use detox as our testing solution in the e2e app and unfortunately it does not allow for running on-device on iOS devices, so near as I can tell there is no way to make an automated test for it. So I think the best path is actually to carefully (that is, take care not to npm/yarn install as it will potentially blow away your changes) reach right into node_modules and then roll up the sleeves and get dirty with the .m and .js files directly in the messaging module It appears based on my understanding of the problem that there are a couple of things: This may actually fail if used on android? There is no android implementation - but this is a tangent: react-native-firebase/packages/messaging/lib/index.js Lines 128 to 130 in 5039759
This implementation which is checking for foreground or background: react-native-firebase/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.m Lines 53 to 55 in 5039759
Is probably best not as a property that is accessed but as something that is determined each time here: react-native-firebase/packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.m Lines 149 to 156 in 5039759
Then it would accurately reflect whether the app is in the background or not? |
(hit enter too soon, updated comment above - https://github.com/ds300/patch-package may be used to test your changes more reliably, and then the same work can be proposed as a PR here?) |
A bit of debugging later... react-native-firebase/packages/messaging/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m Line 52 in c94546d
The docs say that the selector function
but even if we add that, it does not change that this function is never called react-native-firebase/packages/messaging/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m Line 133 in c94546d
So here we never set the isHeadless to falsereact-native-firebase/packages/messaging/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m Line 147 in c94546d
The default YES value is also never called and the only reference we could find for the
I have to say my knowledge about how RN works is even less than how ObjC is working but maybe this is a first hint? |
Right... If I only followed the instructions to update the AppDelegate.m I would have called the |
if i send message with |
Hello 👋, to help manage issues we automatically close stale issues.
|
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information. |
Same here. If i remove content-available in json, isHeadless works fine. |
This issue is surfacing in our production app and redirects users to the blank screen as isHeadless is true when the app is launched from the quit state. Even though we return |
Hello @mikehardy, can you pl suggest something to get rid of this issue? |
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?
Thank you for your contributions. |
Is there any progress here? This issue should not be closed. |
I am experiencing the same issue. When the app opens from pressing the background notification, isHeadless stays true |
Hi, I spent some time investigating this issue and found the solution. The problem comes from updating app properties while the bridge has not been loaded. It's an issue that comes from react native, facebook/react-native#20115 but react-native suggested that they won't be solving it, There's 2 suggested solutions: 1 is to wait for js to load then set the props, but this didn't work for us
2 is to patch react native, which did work for us https://github.com/facebook/react-native/pull/20116/files |
@humaidk2 react-native-firebase definitely has some things that only load after the javascript environment comes up and to my knowledge it has been working reliably. Patching react-native in those files implies a local fork / build of react-native is very painful from a maintenance perspective making a javascript observer a strong preference This notification is used internally in react-native I'm surprised it's not working, they appear to be specifying the bridge as the object to observe though, I wonder if you follow their addObserver pattern it might work better? Examples: |
The issue is that the
isHeadless
flag included in@react-native-firebase/messaging
is unreliable and causes the app to rendernull
when the app is opened. The flag can be true initially when the app is launching but does not update to false when the app is in the foreground.Please see this code snippet which is taken from the docs:
There have been previous discussions around the usage of this flag:
#4163
#4304
Some suggestions to listen to
AppState
rather than use theisHeadless
flag but it's unclear what the best solution is to prevent the app from rendering when it's in a headless state.From reading the discussions, it's clear the
isHeadless
flag causes unpredictable results, is there anything that can be done in the library to fix the flag?Or, can the docs be updated to show a recommended solution?
Project Files
Javascript
Click To Expand
package.json
:# N/A
firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:e.g. 5.4.3
Firebase
module(s) you're using that has the issue:e.g. Instance ID
MessagingTypeScript
?Y/N
&VERSION
YReact Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: