Reputation: 106
Maybe someone knows how to get device token when using OneSignal to receive notifications?
Upvotes: 2
Views: 6988
Reputation: 1197
For React Native getDeviceState
is no longer a function on the latest OneSignal v5.0.3. Here is how you get the subscription ID and subscription token for the user after they have accepted permission:
const subId = OneSignal.User.pushSubscription.getPushSubscriptionId();
const subToken = OneSignal.User.pushSubscription.getPushSubscriptionToken();
Upvotes: 1
Reputation: 747
For Flutter
use this code:
OneSignal.shared.getDeviceState().then((deviceState) {
final pushToken = deviceState.pushToken;
}
Upvotes: 1
Reputation: 8332
If you are using the react native
SDK you can retrieve it from the device state:
const pushToken = (await OneSignal.getDeviceState()).pushToken
Upvotes: 3
Reputation: 106
This is it:
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
@Override
public void idsAvailable(String userId, String registrationId) {
Log.d("debug", "User:" + userId);
if (registrationId != null)
Log.d("debug", "registrationId:" + registrationId);
}
});
It helps to get user id and that is actually a device token.
Upvotes: 5