react-native-firebase onNotificationOpenedApp method not firing
See original GitHub issueBug report
Summary
I’m using react-native-firebase and have done some research, I found that others are also experiencing the same problem:
- https://github.com/invertase/react-native-firebase/issues/3469
- https://github.com/crazycodeboy/react-native-splash-screen/issues/289#issuecomment-502406454
I previously used react-native-splash-screen
on this project, and onNotificationOpenedApp
worked on android but not on ios, then I did some digging and found this comment saying to use react-native-bootsplash
instead, so I switched to this library but now it no longer works on both android and ios. So I thought it might be related to this library…
on my index.js
I have:
import 'setDefaults';
import { AppRegistry } from 'react-native';
import { name as appName } from './app.json';
import Main from 'Main';
AppRegistry.registerComponent(appName, () => Main);
Then the Main.js
:
import React from 'react';
import App from 'App';
function Main ({ isHeadless }) {
if (isHeadless) return null;
return <App />;
}
export default React.memo(Main);
On App.js
,
Outside the App component
:
messaging().setBackgroundMessageHandler(async notif => {
console.log('background notif!', notif);
});
Then in the App component
I have this effect:
React.useEffect(() => {
if (!wasNotifsAllowed) return;
(async () => {
const token = await iid().getToken();
console.log('token', token);
})();
const listeners = [
messaging().onMessage(async notif => {
console.log('foreground notif!', notif);
}),
messaging().onNotificationOpenedApp(async notif => {
console.log('opened notif!', notif);
}),
messaging().onTokenRefresh(async token => {
console.log('new token', token);
})
];
return () => {
listeners.forEach(unsubscribe => {
unsubscribe();
});
};
}, [wasNotifsAllowed]);
I handle the wasNotifsAllowed
on App.js
as well on the following effect:
React.useEffect(() => {
(async () => {
const authorizationStatus = await messaging().requestPermission({
sound: true,
badge: true
});
const wasNotifsAllowed =
authorizationStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authorizationStatus === messaging.AuthorizationStatus.PROVISIONAL;
setState({ wasNotifsAllowed });
})();
}, []);
messaging().onMessage(callback)
works well.messaging().setBackgroundMessageHandler(callback)
also works well on android, I’m seeing console logs, on ios, I don’t see the console logs but I am able to receive the notification even when the app is on killed state.
My main/AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shine.satellite">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="<url-here>"
android:pathPrefix="/android/${applicationId}/callback"
android:scheme="${applicationId}" />
</intent-filter>
</activity>
<activity
android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
android:theme="@style/BootTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat">
</activity>
</application>
</manifest>
Environment info
react-native info
output:
System:
OS: macOS 11.0.1
CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Memory: 25.56 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 15.2.0 - /var/folders/zg/f6_98ss10lj5b841clyhsxlh0000gn/T/yarn--1608166773585-0.5611083345771732/node
Yarn: 1.22.10 - /var/folders/zg/f6_98ss10lj5b841clyhsxlh0000gn/T/yarn--1608166773585-0.5611083345771732/yarn
npm: 7.0.8 - ~/.nvm/versions/node/v15.2.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.0 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.3, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
Android SDK:
API Levels: 24, 26, 28, 29, 30
Build Tools: 28.0.3, 29.0.2, 30.0.2
System Images: android-24 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.6953283
Xcode: 12.3/12C33 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_275 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: ^16.14.0 => 16.14.0
react-native: 0.63.3 => 0.63.3
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Library version: x.x.x
Steps to reproduce
- Init React-Native app
- Configure the app to use firebase
- Configure the app to use react-native-bootsplash
Describe what you expected to happen:
- react-native-bootsplash should work with firebase.
Reproducible sample code
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Yeah I got it now @zoontek, I was mistaken, I was killing the app instead of putting it on the background. It works flawlessly. Thanks 🙇🏻
I’m obviously heavily involved in react-native-firebase, I wrote the comments on the old splash screen issue after initially figuring out and posting the root cause, and recommend using this library plus I help @zoontek here - especially on cross over issues like this. I saw the comment you left on the issue on react-native-firebase repo linking here and I just have to say: I don’t see this problem in my app.
I recommend on the linked issue that you make a completely clean demo starting from scratch (e.g. https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh) where you try to reproduce it, and I further recommend that if you can reproduce it that you then post that demo on github so we may see it.
Last time this happened someone had integrated (but not mentioned!) that they had integrated onesignal or some other package that was eating the Intent extras and not mentioned it, which wasted a lot of time. I won’t investigate this without a reproduction I can fully see