React Native OneSignal: deviceState doesn't show subscribed until second time user logs in

491 Views Asked by At

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?

[email protected] [email protected]

0

There are 0 best solutions below