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

查看:96
本文介绍了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上运行.但是有些开发人员喜欢

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 }

显然使这种方式破了.

另一个实施错误的示例(已经进行了编辑,包括了正确的实施).

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天全站免登陆