本文介绍了一个信号-idsAvailable已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OneSignal的最新生成版本会生成类似" idsAvailable "的警告.如何使用 getPermissionSubscriptionState()代替idsAvailable来获得"playerID",如下所示?

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保留了非常好的文档.

OneSignal keeps really good documentation.

对于android,您可以使用idsAvailable方法获取用户ID,该方法将返回用户ID和注册ID.

For android you can get userIDs by using the idsAvailable method which returns the userID and registrationID.

userID或playerID是OneSignal UUID格式的字符串. (每个应用每个设备唯一)registrationID是Google分配的标识符(每个应用程序每个设备唯一,并且重新安装时有更改).

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

对于iOS,您可以通过相同的方式获取用户ID,但在本机iOS SDK的2.5.0+版本中,添加了getPermissionSubscriptionState方法和addSubscriptionObserver.

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.

您可以通过以下方式获取Swift的OSPermissionSubscriptionState:

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

对于Objective-C:

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

这篇关于一个信号-idsAvailable已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 17:13