After I press back button and close the app, opened event does not fire.
All other cases works great
We're experiencing the same issue. Is there a workaround yet?
@getconcar I found a workaround. It is not the best way but worked for me.
private void notifyNotificationOpened(Bundle bundle) {
try {
// Add delay here to avoid this problem
Handler handler = new Handler();
final JSONObject jsonObject = new JSONObject(bundle.getString("result"));
handler.postDelayed(new Runnable() {
@Override
public void run() {
sendEvent("remoteNotificationOpened", RNUtils.jsonToWritableMap(jsonObject));
}
}, 500);
} catch(Throwable t) {
t.printStackTrace();
}
}
RNOneSignal.java has an event called notifyNotificationOpened. Here it send notification event to React Native. But I've found out that it needs some time before sending this event to bridge.
So I basically made some delay.
The reason why opened is not called could be this:
From the API the suggested usage is this:
componentWillMount() {
OneSignal.addEventListener('opened', this.onOpened);
}
componentWillUnmount() {
OneSignal.removeEventListener('opened', this.onOpened);
}
When your App goes in background, the component gets unmounted and the listener removed, so you can't receive any message.
You can remove the removeEventListener from the componentWillUnmount, then the callback will be called.
I see different behaviours if the app is killed or if the app is only in background, this could be the reason why sometimes it works.
@cihancil Awesome, that fixed it for me with more than 1000ms delay - 500ms did not work for some reason.
Maybe you could create a pull-request with these changes because I think in combination with Redux it will not work in any other way on Android.
@cihancil Hi cihanccil.
I meet the same. When App is closed or killed, on Open event is not called. I don't understand your solution. Why will delaying sendEvent("remoteNotificationOpened", ...) help App called onOpenEvent? Please explain me. Thanks in advance.
@cihancil Thanks, this worked for me with 1000ms delay.
@vantb9x I meet same problem, Do you have a way to solve it?
@lehoi2195 I solved this problen folowing @cihancil 's way: delay function "remoteNotification" in RNOneSignal.java. The timeout depends on you. I set timeout = 4000 in my app. If you don't want set timeout, I think we should edit native code in both java and objective C. Instead of delaying function "remoteNotificationOpened", we have a flag to mark. When app is mounted, app will call native function to notify app mounted.
But there is a problem that react-native-onesignal has not yet handled.
If app is background or closed, I still receive notification. But if app is killed by swiping up, there are some android device which receive notification, the others don't receive. Because the settings on android devices (version, manufacturer...) are different.
@vantb9x Yeah. thanks you for solution 馃挴
I have the same issue even in v3.9.1. When app is minimized with back button, click on notification will not fire opened event
Most helpful comment
@getconcar I found a workaround. It is not the best way but worked for me.
}
RNOneSignal.java has an event called notifyNotificationOpened. Here it send notification event to React Native. But I've found out that it needs some time before sending this event to bridge.
So I basically made some delay.