OneSignal保持真正的好文件。
對於android,您可以使用idsAvailable
方法獲取用戶標識,該方法返回用戶標識和註冊標識。
userID aka playerID是OneSignal UUID格式化的字符串。 (每個應用每個設備都是唯一的) registrationID是Google分配的標識符(每個應用每個設備都是唯一的,並在重新安裝時發生更改)。
對於iOS,您可以以相同方式獲取用戶標識,但在本機iOS SDK的2.5.0+版本中添加了getPermissionSubscriptionState方法和addSubscriptionObserver。
你可以得到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
}
}