gpt4 book ai didi

apple-push-notifications - iOS 13是否具有获取设备通知 token 的新方法?

转载 作者:行者123 更新时间:2023-12-03 15:18:00 25 4
gpt4 key购买 nike

所以我的 friend 从OneSignal收到了这封电子邮件

Due to a change that may occur as part of the upcoming iOS 13 release, you must update to the latest version of the iOS SDK before building your app with Xcode 11. All of OneSignal’s wrapper SDKs including React Native, Unity, and Flutter have been updated as well. The reason for this is that Xcode 11, which is being released alongside iOS 13, breaks a common technique that apps and libraries like OneSignal were using to get a push token for the device. If you do not use our new SDK then new users will not be able to subscribe to notifications from your app.



我对此感到好奇。

这是我们在iOS 12上获取设备通知 token 的方式
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
var token = ""
for i in 0..<deviceToken.count {
token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])
}
print("Notification token = \(token)")
}

在iOS 13上获取它的正确方法是什么?
我应该为当前开发的应用程序使用新方法还是旧方法仍然可行?

最佳答案

这样做的方式很好,它应该可以继续在iOS 13上运行。但是有些开发人员喜欢this。要将Data转换为基数为16的字符串,他们调用description,返回的内容类似于

<124686a5 556a72ca d808f572 00c323b9 3eff9285 92445590 3225757d b83997ba>

然后他们修剪 <>并删除空格。

在iOS 13上,在 token 数据上调用的 description返回类似
{ length = 32, bytes = 0xd3d997af 967d1f43 b405374a 13394d2f ... 28f10282 14af515f }

这显然使这种方式被打破了。

错误实现的 Another example(已进行编辑以包括正确的实现)。

this thread中可以找到更多示例。

关于apple-push-notifications - iOS 13是否具有获取设备通知 token 的新方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57839723/

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