One signal - idsAvailable deprecated

The latest version of the OneSignal assembly generates a warning like " idsAvailable " is deprecated. How can I get the 'playerID' using getPermissionSubscriptionState () instead of idsAvailable, as I did below?

    OneSignal.idsAvailable({ (userId, pushToken) in

        if (pushToken != nil) {

            if let playerID = userId {

                // do something

            }
        }
    })
+6
source share
3 answers

OneSignal stores really good documentation.

For android, you can get user IDs using a method idsAvailablethat returns the user ID and registration ID.

userID aka playerID - UUID OneSignal. ( ) registrationID - Google ( ).

iOS , 2.5.0+ SDK iOS getPermissionSubscriptionState addSubscriptionObserver.

OSPermissionSubscriptionState Swift :

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)")

Objective-C:

OSPermissionSubscriptionState* status = [OneSignal getPermissionSubscriptionState];
status.permissionStatus.hasPrompted
status.permissionStatus.status

status.subscriptionStatus.subscribed
status.subscriptionStatus.userSubscriptionSetting
status.subscriptionStatus.userId
status.subscriptionStatus.pushToken

, :

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
    }
}
+8

userIdis the same as playerIdcomparing all this in one example of the Analytics (singleton) class that I use in my Swift 4 application:

class Analytics : NSObject, OSSubscriptionObserver {

    ///the singleton
    static let shared = Analytics()


    func setupOneSignal(launchOptions: [UIApplicationLaunchOptionsKey : Any]?) {
        OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)
        OneSignal.add(self as OSSubscriptionObserver)

        let settings : [String : Any] = [kOSSettingsKeyInAppLaunchURL : false]
        OneSignal.initWithLaunchOptions(
            launchOptions,
            appId:Environment.oneSignalAppId,
            handleNotificationReceived: {
                (osnotification) in
               //.....
        },
            handleNotificationAction: {
                (osNotificationOpenedResult) in
               //.....

        },
            settings: settings)
    }

    func onOSSubscriptionChanged(_ stateChanges: OSSubscriptionStateChanges!) {
        if  let state = OneSignal.getPermissionSubscriptionState(),
            let userId = state.subscriptionStatus.userId,
            let pushToken = state.subscriptionStatus.pushToken {
            print("onesignal.userId : \(userId)")
            print("onesignal.pushToken : \(pushToken)")
        }
    }

}
0
source

Source: https://habr.com/ru/post/1016321/


All Articles