OneSignal's latest build version generate a warning like 'idsAvailable' is deprecated. How can I get 'playerID' using getPermissionSubscriptionState() instead idsAvailable as I did below?
OneSignal.idsAvailable({ (userId, pushToken) in
if (pushToken != nil) {
if let playerID = userId {
// do something
}
}
})
OneSignal keeps really good documentation.
For android you can get userIDs by using the idsAvailable
method which returns the userID and registrationID.
userID aka playerID is a OneSignal UUID formatted string. (unique per device per app) registrationID is a Google assigned identifier (unique per device per app and changes on reinstalls).
For iOS, you can get the userIDs in the same way but in version 2.5.0+ of the native iOS SDK added getPermissionSubscriptionState method and addSubscriptionObserver.
You can get the OSPermissionSubscriptionState for Swift as follows:
let status: OSPermissionSubscriptionState = OneSignal.getPermissionSubscriptionState()
let hasPrompted = status.permissionStatus.hasPrompted
print("hasPrompted = \(hasPrompted)")
let userStatus = status.permissionStatus.status
print("userStatus = \(userStatus)")
let isSubscribed = status.subscriptionStatus.subscribed
print("isSubscribed = \(isSubscribed)")
let userSubscriptionSetting = status.subscriptionStatus.userSubscriptionSetting
print("userSubscriptionSetting = \(userSubscriptionSetting)")
let userID = status.subscriptionStatus.userId
print("userID = \(userID)")
let pushToken = status.subscriptionStatus.pushToken
print("pushToken = \(pushToken)")
For Objective-C:
OSPermissionSubscriptionState* status = [OneSignal getPermissionSubscriptionState];
status.permissionStatus.hasPrompted
status.permissionStatus.status
status.subscriptionStatus.subscribed
status.subscriptionStatus.userSubscriptionSetting
status.subscriptionStatus.userId
status.subscriptionStatus.pushToken
So your above code will now look something like this:
let status: OSPermissionSubscriptionState = OneSignal.getPermissionSubscriptionState()
let userID = status.subscriptionStatus.userId
print("userID = \(userID)")
let pushToken = status.subscriptionStatus.pushToken
print("pushToken = \(pushToken)")
if pushToken != nil {
if let playerID = userID {
// do something
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With