iOS 13 是否有获取设备通知令牌的新方法? [英] Does iOS 13 has new way of getting device notification token?

查看:28
本文介绍了iOS 13 是否有获取设备通知令牌的新方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So my friend got this email from OneSignal

由于即将发布的 iOS 13 版本中可能发生的变化,在使用 Xcode 11 构建应用程序之前,您必须更新到最新版本的 iOS SDK.OneSignal 的所有包装 SDK,包括 React Native、Unity 和Flutter 也已更新.这样做的原因是,与 iOS 13 一起发布的 Xcode 11 打破了 OneSignal 等应用程序和库用来获取设备推送令牌的常用技术.如果您不使用我们的新 SDK,新用户将无法从您的应用订阅通知.

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 上获取设备通知令牌的方式

This is the way we got the device notification token on iOS 12

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 上获取它的正确方法是什么?我应该为我目前正在开发的应用程序采用新方法还是旧方法仍然可以?

Whats the proper way to get it on iOS 13? Should I do the new way for my currently developing apps or the old way is still fine?

推荐答案

你这样做的方式很好,它应该可以继续在 iOS 13 上工作.但是一些开发者会像 这个.要将Data 转换为base-16 字符串,他们调用description,它返回类似

The way you do it is fine and it should continue to work on iOS 13. But some developers do it like this. To convert Data into base-16 strings, they call description, which returns something like

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

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

And then they trim < and > and remove spaces.

在 iOS 13 上,对令牌数据调用的 description 返回类似

On iOS 13 the description called on token data returns something like

{ length = 32, bytes = 0xd3d997af 967d1f43 b405374a 13394d2f ... 28f10282 14af515f }

这显然打破了这种方式.

Which obviously makes this way broken.

另一个错误实施示例(已编辑以包括正确实施).

Another example of wrong implementation (already edited to include correct implementation as well).

可能会在此主题中找到更多示例.

Some more examples might be found in this thread.

这篇关于iOS 13 是否有获取设备通知令牌的新方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆