How to get One Signal unique user id in Mobile? How to get One Signal unique user id in Mobile? ios ios

How to get One Signal unique user id in Mobile?


Got the unique Id of OneSignal by using the following code which is in official site of OneSignal.

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);        }    });

Refer:

Getting code in Official Site

This Above Code is Deprecated. Please use the below code.

String UUID = OneSignal.getPermissionSubscriptionState().getSubscriptionStatus().getUserId()


The above solution for android is deprecated Use:

OSPermissionSubscriptionState status = OneSignal.getPermissionSubscriptionState();status.getSubscriptionStatus().getUserId();


Android Java

String userId = OneSignal.getDeviceState().getUserId();

Android Kotlin

val oneSignalUserID = OneSignal.getDeviceState()!!.userId

iOS OneSignal Version 3.6.0

guard let userID = OneSignal.getDeviceState().userId else { return }

iOS Old OneSignal Version

let status: OSPermissionSubscriptionState = OneSignal.getPermissionSubscriptionState()    if let id = status.subscriptionStatus.userId {    oneSignalPlayer_ID = id    print("\nOneSignal UserId:", id)}


matomo