-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
onNotification not called when the app is first opened from notification tap #1955
Comments
Hi @cristianoccazinsp |
I'm pretty much using the example code, but
|
You can check: |
This is for both Android and iOS, and only for local notifications (not using remote). Calling |
Hi @cristianoccazinsp |
Just to be sure: if you completely kill the app (swipe it out) while the notification is still visible, then tap the notification, the app opens, Also, on iOS, |
I dig into the link provided, I found this: You can try in Release mode, this should work. |
Release mode may solve it for iOS, but what about Android? So far the only work around that worked for me was to use |
For Android,
@Override
public void onNewIntent(Intent intent) {
...
super.onNewIntent(intent);
...
} |
Main activity is clean, and no custom splash screen (we are just using a background image)
|
Landed on the same issue, for remote notifications, the onNotification is not called on tapping the notification. However, it gets called when the notification arrives. Is there any other method that is triggered on clicking the notification from the tray? OS: Android The implementation is pretty much the same as mentioned above. I went through many other issues that were reported but could not find a solution for this. Any help is appreciated. Thanks in advance. |
I'm having the exact same problem but my <activity android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:launchMode="singleTask"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"
android:exported="true">
<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:scheme="trique"/>
</intent-filter>
</activity>
And this is my /* eslint-disable curly */
/* eslint-disable prettier/prettier */
/**
* @format
*/
import { AppRegistry, AppState, Platform } from 'react-native';
import App from 'commons/src/App';
import { name as appNameJson } from './app.json';
import PushNotification from 'react-native-push-notification';
import triquestore from 'commons/src/store';
import { providers } from 'commons/src/services/Auth.service';
import { saveNotification } from 'commons/src/store/notifications';
const appName = Platform.OS === 'ios' ? appNameJson : 'com.trique.app';
const handleOnNotification = (notification) => {
if (notification) {
console.log('NOTIFICATION_RECIEVED', JSON.stringify(notification));
if (!notification.ignoreInForeground && !notification.data.actionIdentifier) {
console.log('PUSH_NOTIFICATION_ACCEPTED');
triquestore.dispatch(saveNotification(notification));
console.log('PUSH_NOTIFICATION_STORED');
const payload = JSON.parse(notification.data.payload);
if (Platform.OS === 'android') {
PushNotification.localNotification({
...notification,
channelId: 'com.trique.app',
title: payload.notification.title,
message: payload.notification.body,
ignoreInForeground: true,
});
console.log('LOCAL_NOTIFICATION_GENERATED_ANDROID');
} else if (AppState.currentState === 'background') {
PushNotification.localNotification({
...notification,
title: payload.notification.title,
message: payload.notification.body,
});
console.log('LOCAL_NOTIFICATION_GENERATED_IOS');
}
} else {
console.log('LOCAL_NOTIFICATION_CLICKED', JSON.stringify(notification));
}
}
};
PushNotification.configure({
onRegister: function (token) {
providers.GOOGLE.fcmToken = token.token;
},
onNotification: handleOnNotification,
onRegistrationError: function (err) {
console.error(err.message, err);
},
//popInitialNotification: true,
requestPermissions: true,
});
PushNotification.createChannel(
{
channelId: (Platform.OS === 'android') ? 'com.trique.app' : 'com.diofy.trique',
channelName: 'Trique',
},
(created) => {
if (created) console.log(`createChannel returned '${created}'`);
},
);
PushNotification.popInitialNotification(handleOnNotification);
AppRegistry.registerComponent(appName, () => App); Everything works as expected with the app in foreground and background, the notification is even stored in redux, getting the desired output.. But when i tap the [Fri May 28 2021 01:23:49.445] LOG NOTIFICATION_RECIEVED {"foreground":false,"userInteraction":false,"id":"737196777","data":{"payload":"{\"relatedId\":3,\"content\":\"\",\"name\":\"FerTrique\",\"people\":[{\"id\":3,\"name\":\"Alejandro Albertengo\",\"avatar\":{\"uri\":\"https://firebasestorage.googleapis.com/v0/b/triqueapp.appspot.com/o/3%2Fprofile.png?alt=media&token=87883367-cde2-4b9a-9004-0aca3e35cbd6\"}}],\"type\":8,\"notification\":{\"title\":\"Te han comenzado a seguir\",\"body\":\"Alejandro Albertengo ha comenzado a seguirte\"}}"}}
[Fri May 28 2021 01:23:49.446] LOG PUSH_NOTIFICATION_ACCEPTED
[Fri May 28 2021 01:23:49.446] LOG PUSH_NOTIFICATION_STORED
[Fri May 28 2021 01:23:49.447] LOG LOCAL_NOTIFICATION_GENERATED_ANDROID
[Fri May 28 2021 01:23:49.447] LOG Loaded react-native-ffmpeg-android-arm64-v8a.
[Fri May 28 2021 01:24:11.503] LOG Running "com.trique.app" with {"rootTag":1} |
I'm facing this exact issue. |
We were using <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.INFO" />
</intent-filter> so in total that now looks like this:<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:windowSoftInputMode="adjustResize"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.INFO" />
</intent-filter>
<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:scheme="nora"/>
</intent-filter>
</activity>
<activity
android:name=".SplashScreenActivity"
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> |
I faced the same problem and for me the solution was to turn off the debug mode on the real device and after that the onNotification method started working. |
Bug
Environment info
react-native info
output:Library version: 7.2.3
Steps To Reproduce
The above code only runs when the notification is tapped and if the app was previously opened. However, if the app was not opened, it never runs.
I'm trying to handle the case when the user taps on the notification and the app wasn't opened / was killed, in order to react to it accordingly.
I see from RN logs that an
initialProps
object is added when the app opens from the notification on iOS, could this be used to add extra info?Thanks!
The text was updated successfully, but these errors were encountered: