gpt4 book ai didi

ios - 一个信号 - idsAvailable 已弃用

转载 作者:搜寻专家 更新时间:2023-10-30 21:53:11 26 4
gpt4 key购买 nike

OneSignal 的最新构建版本生成警告,如“idsAvailable”已弃用。我如何使用 getPermissionSubscriptionState() 而不是 idsAvailable 来获取“playerID”,就像我在下面所做的那样?

    OneSignal.idsAvailable({ (userId, pushToken) in

if (pushToken != nil) {

if let playerID = userId {

// do something

}
}
})

最佳答案

OneSignal 保留了非常好的文档。

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

userID aka playerID 是 OneSignal UUID 格式的字符串。 (每个应用程序每个设备唯一)registrationID 是 Google 分配的标识符(每个设备的每个应用程序都是唯一的,并且在重新安装时会发生变化)。

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

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

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

关于ios - 一个信号 - idsAvailable 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43230152/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com