1

In my React Native app, I initialize my OneSignal instance with OneSignal.setAppId(), and then attempt to grab the UserID using OneSignal.getDeviceState(). My code looks like this:

OneSignal.setAppId("<AppID>");
let getDeviceState = async () => {
  const deviceState = await OneSignal.getDeviceState()
  console.log(deviceState)
}
getDeviceState();

When I first install the app, it returns this:

{"hasNotificationPermission": true, "isEmailSubscribed": false, "isPushDisabled": false, "isSMSSubscribed": false, "isSubscribed": false}

On all subsequent loads, it returns this:

{"hasNotificationPermission": true, "isEmailSubscribed": false, "isPushDisabled": false, "isSMSSubscribed": false, "isSubscribed": true, "pushToken": <...>, "userId": <...>}

So on the first load, I can't access pushToken or userId. Is it just that they haven't had time to load yet? Is there an event handler I can access when they do?

react-native@0.64.4 react-native-onesignal@4.0.6

gkeenley
  • 6,088
  • 8
  • 54
  • 129

0 Answers0