React-native-onesignal: onOpened and onReceive not firing

Created on 17 Aug 2018  Â·  25Comments  Â·  Source: OneSignal/react-native-onesignal

Description:
I've upgraded from 3.2.5 to 3.2.6 which resolved https://github.com/geektimecoil/react-native-onesignal/issues/583, but still can't get the onReceived and onOpened functions to fire when app is minimized. The functions do fire if app is completely shut down. Confirmed its working on iOS.

I've tried yarn remove/yarn add and react-native unlink/react-native link but still not seeing it working

Environment

Steps to Reproduce Issue:

  1. Start app on Android
  2. Minimize app
  3. Trigger push notification
  4. Open app by clicking push notificaition. No event fired
  5. Quit app completely
  6. Trigger push notification
  7. Open app by clicking push notificaition. Event fired

Help Wanted

Most helpful comment

I've found how to solve this problem.
I use latest version of react-native-onesignal.

Just delete 2 lines below :

@Override
public void onHostDestroy() {
//OneSignal.removeNotificationOpenedHandler();
//OneSignal.removeNotificationReceivedHandler();
}

I have compared the previous version with the current version and viola! that's where the main problem is.

All 25 comments

+1

I have to go back to 3.2.4

@pacozaa Did going back to 3.2.4 work for you? I still am seeing the same issue.

After doing more research I've found that if the initial notification happens from when the app is totally shut down, any notifications received when the app is minimized cause the handlers to fire.

But if I start the app, minimize without receiving a notification, the handlers are not fired when a notification comes in

@burdell I followed your steps to reproduce, but it works for me every time. Are you certain you tested on 3.2.6...? How do you know these handlers are not firing?

Can you test out our demo project with 3.2.6 and tell me if the issue occurs?

@burdell yes it is.

@Nightsd01 how do you run the demo project?

@pacozaa It's in the examples/RNOneSignal folder. You can run yarn, then run react-native link react-native-onesignal.

Once that's done, you should be able to just replace with your App ID in index.js and should be able to run the project. You can try modifying the SDK versions and so on to match what you are using in your real app.

Please let me know if you can reproduce this issue in our demo project or not - as of now I have not been able to reproduce this and 99% of the time it is user error - but it's possible it's a bug that only effects certain versions/devices as well.

Sorry, been away from this for a few weeks but I was able to verify that it was working in the demo app

Couldn't ever get it to work in our app though even after going through and trying to copy how the demo app was setup 🤷‍♂️

I'm seeing different, but related behavior to what's described here on Android (3.2.7)
1, Foreground: onOpened/onReceived fire correctly
2, Background: onOpened/onReceived fire correctly
3, Dismissed (swiped-away from multitask switcher): onOpened/onReceived do not fire

On iOS, all of 1, 2, and 3 work correctly.

I am able to reproduce this behavior in the demo app on [email protected], which leads me to believe that this may be a recent regression on Android. Possibly related to the recent fixes for background?

I was experiencing the same issue as @burdell, but I managed to solve it.

On iOS, everything worked flawlessly. But OnOpened wouldn’t fire on Android if the app was in inactive (background or killed). I’ve experienced that it usually fires once every session, but once it’s put in the background again, and tap on a new notification, it just shows the app. What I found weird is that there are two instances of my application after I tapped on the notification.

  1. react-native run-android
  2. app cold starts (main instance)
  3. press home button to put app in background
  4. trigger & tap on new notification
  5. onOpened IS called, but the app cold starts, despite the fact it was running 10 seconds before
    NOTE: if i check my recents I have two instances of the application
  6. press home to put app in background (new instance disappears from recents)
  7. trigger & tap on new notification
  8. onOpened is NOT called, app cold starts again
    NOTE: in the recents there is only a single instance

I suspected this behaviour could be the root of the issue, and all I had to do to fix this is to modify the AndroidManifest.xml from:

<activity
        android:name=".MainActivity”
        android:launchMode=“singleTop”
        >

to:


<activity
        android:name=".MainActivity”
        android:launchMode="singleInstance"
        >

After this, everything works perfectly on Android. I’m not sure why the example uses singleTop.

What I did:

  • I used the example app as a template in my project
  • I set up the redux rehydration to make sure everything happens after the store is set up (as seen here https://github.com/geektimecoil/react-native-onesignal/issues/332#issuecomment-341326624 )
  • Change to singleInstance

I'm using:
"react-native": "0.55.4",
"react-native-onesignal": “3.2.7”


@mcmar Some android device makers will not allow your app to execute received callback if the app has been intentionally dismissed/terminated by the user. That would explain why the received callback didn't work for you - but you are also saying opened didn't work as well?

9/10 times when a user reports this issue it is because they have a bug in their code _inside_ of the callback, or it's because of their launchmode/view hierarchy has an issue. We have not seen a user that has been able to reproduce in our example project.

When you reproduce in our example project, can you please zip up the project exactly as it was when you reproduced and post a link here?

Can you also post more information such as a logcat when you open the notification for the first 15 seconds? Can you also tell us what version/s of android you are able to reproduce this issue on?

I've found how to solve this problem.
I use latest version of react-native-onesignal.

Just delete 2 lines below :

@Override
public void onHostDestroy() {
//OneSignal.removeNotificationOpenedHandler();
//OneSignal.removeNotificationReceivedHandler();
}

I have compared the previous version with the current version and viola! that's where the main problem is.

I also have the same problem.
I've tested with samsung devices and android 7 or lower and everything is fine.
Though when I test on a Motorola with android 8 it doesn't work.

@Nightsd01 would you have any idea why this might happen?

Thanks

I was experiencing the same issue as @burdell, but I managed to solve it.

On iOS, everything worked flawlessly. But OnOpened wouldn’t fire on Android if the app was in inactive (background or killed). I’ve experienced that it usually fires once every session, but once it’s put in the background again, and tap on a new notification, it just shows the app. What I found weird is that there are two instances of my application after I tapped on the notification.

  1. react-native run-android
  2. app cold starts (main instance)
  3. press home button to put app in background
  4. trigger & tap on new notification
  5. onOpened IS called, but the app cold starts, despite the fact it was running 10 seconds before
    NOTE: if i check my recents I have two instances of the application
  6. press home to put app in background (new instance disappears from recents)
  7. trigger & tap on new notification
  8. onOpened is NOT called, app cold starts again
    NOTE: in the recents there is only a single instance

I suspected this behaviour could be the root of the issue, and all I had to do to fix this is to modify the AndroidManifest.xml from:

<activity
        android:name=".MainActivity”
        android:launchMode=“singleTop”
        >

to:


<activity
        android:name=".MainActivity”
        android:launchMode="singleInstance"
        >

After this, everything works perfectly on Android. I’m not sure why the example uses singleTop.

What I did:

  • I used the example app as a template in my project
  • I set up the redux rehydration to make sure everything happens after the store is set up (as seen here #332 (comment) )
  • Change to singleInstance

I'm using:
"react-native": "0.55.4",
"react-native-onesignal": “3.2.7”

This did not work for me.
When app is in background i.e app is minimized and in memory, OpOpened does not fire. This happens only in Oreo and above. The notification when clicked on it, the app takes about 10-20 seconds to launch.

Hi all,

I am having a similar issue. On both iOS and Android, when I receive a push notification, I click on the notification and it opens the app. I created a code that when the app opens and it checks if there is a push notification, then opens a different screen to display the notification.

Now the issue is, that the first time when I click on the notification the app opens, but nothing happens after that. Then closing the app, reopen it and suddenly the screen appears with the notification text shown.

So is the onOpened function not working the first time? This happens on iOS and Android.

@meetyourdev @udarts ,
Are you still having this issue?

Any answers to the problem?

This still happens. Any solution?

OnReceived is still not firing when app is background. Any solution?

Howdy,
We haven't been able to reproduce this issue. Does anyone have an example project we could test with?

@rgomezp I’m sorry. This does not happen always but when several notifications come to the mobile or when app was in background for few hours this happens. On both iOS and Android. This doesn’t happen always but regularly.

@samitha9125 ,
The received event only fires if the app is in foreground. Take a look at our "events" section from our documentation .

@mauricioalexandres ,
Can you provide some details regarding your specific implementation?

@rgomezp Oh thank you for that. I didn’t see that earlier. So how can I get incoming notifications when my app is in the background?

Howdy,
We have a section describing how to implement Background Notifications. I'll close the issue since this isn't really an ongoing issue. Also, consider reaching out through our official OneSignal.com support channel for quicker support.

Enjoy!

Hello.. i know this is an old issue but can you guide me? I already created an incoming call screen but the problem is that the incoming call screen wont display when the app is inactive.. so is there other way to display it even it is inactive?

Was this page helpful?
0 / 5 - 0 ratings