react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

[question]: OneSignal PlayerID Null on Initial App Startup (Android)

Open maoryadin opened this issue 2 years ago • 4 comments

How can we help?

Hello everyone,

I'm facing an issue on Android where the OneSignal PlayerID is always null during the initial startup of the application (i.e., the first time after installation). As a result, I am unable to save the PlayerID to my database until the second launch of the app.

Steps to Reproduce:

Install the application on an Android device. Launch the application. Attempt to retrieve and save the OneSignal PlayerID. (OneSignal.getDeviceState()) Actual Behavior: The OneSignal PlayerID is null on the initial launch, which prevents its storage in the database.

Expected Behavior: The OneSignal PlayerID should be available during the initial launch of the application, allowing it to be saved in the database right away.

I'm looking for guidance on how to handle this situation. What can I do to ensure that the PlayerID is available and savable on the first launch? Any suggestions or best practices would be highly appreciated.

Thank you in advance for your help!

Environment: OneSignal SDK version: 4.5.1

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

maoryadin avatar Jun 23 '23 10:06 maoryadin

Hi @maoryadin, thanks for reaching out with your question.

If getDeviceState() is called too early it will be null or not available. There is a server call to register the device and get a playerID.

You can use the addSubscriptionObserver method to get a playerID from OneSignal when a notification subscription property changes. Does this fulfill your needs?

Thanks!

nan-li avatar Jun 25 '23 22:06 nan-li

Hi @maoryadin, thanks for reaching out with your question.

If getDeviceState() is called too early it will be null or not available. There is a server call to register the device and get a playerID.

You can use the addSubscriptionObserver method to get a playerID from OneSignal when a notification subscription property changes. Does this fulfill your needs?

Thanks!

Does the addSubscriptionObserver should be defined before OneSignal.SetAppId? Because i think if it will be defined after, it will not be triggered..

maoryadin avatar Jun 26 '23 11:06 maoryadin

Hi @maoryadin, addSubscriptionObserver should be added after OneSignal.initWithContext.

Did you test and it is not being triggered for you?

nan-li avatar Jun 26 '23 20:06 nan-li

@maoryadin just checking to see if you received our previous response?

jennantilla avatar Jul 18 '23 19:07 jennantilla