gpt4 book ai didi

ios - 如何在 iOS 中获取 One Signal 用户的唯一玩家 ID?

转载 作者:IT王子 更新时间:2023-10-29 05:22:20 27 4
gpt4 key购买 nike

如何在 iOS 中检索 OneSignal 用户的唯一播放器 ID?我只在 OneSignal 官方文档中找到了 iOS SDK 设置。

如有建议,不胜感激。

最佳答案

您需要使用 OneSignal 的观察者,例如 OSSubscriptionObserver

// Add OSSubscriptionObserver after UIApplicationDelegate
class AppDelegate: UIResponder, UIApplicationDelegate, OSSubscriptionObserver {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Add your AppDelegate as an subscription observer
OneSignal.add(self as OSSubscriptionObserver)
}

// After you add the observer on didFinishLaunching, this method will be called when the notification subscription property changes.
func onOSSubscriptionChanged(_ stateChanges: OSSubscriptionStateChanges!) {
if !stateChanges.from.subscribed && stateChanges.to.subscribed {
print("Subscribed for OneSignal push notifications!")
}
print("SubscriptionStateChange: \n\(stateChanges)")

//The player id is inside stateChanges. But be careful, this value can be nil if the user has not granted you permission to send notifications.
if let playerId = stateChanges.to.userId {
print("Current playerId \(playerId)")
}
}
}

为了更好的解释,这里是 addSubscriptionObserver 的文档

关于ios - 如何在 iOS 中获取 One Signal 用户的唯一玩家 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44428425/

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