gpt4 book ai didi

ios - 推送通知未注册到 iOS 13 上的应用程序

转载 作者:行者123 更新时间:2023-12-02 03:23:21 26 4
gpt4 key购买 nike

我构建了我的应用程序,并在 didRegisterForRemoteNotificationsWithDeviceToken 中放置了一个断点,但它没有被触发。它在其他版本的 iOS 上运行良好。

这是 iOS 13 中的错误还是我错过了 iOS 13 中的新功能?

我使用 Xcode Beta 6 和 iOS 13 beta 8。

最佳答案

重新连接wifi或者切换wifi和蜂窝数据也可以解决上述问题。

此外,iOS 13 中的以下更改影响了推送通知的实现。

在 iOS 13 之前,我们很多人都这样做

(deviceToken as NSData).description 
// Used to return as follows

"<965b251c 6cb1926d e3cb366f dfb16ddd e6b9086a 8a3cac9e 5f857679 376eab7C>"

let tokenData = deviceToken as NSData
let token = tokenData.description

let token = "\(deviceToken)".replacingOccurrences(of: " ", with: "")
.replacingOccurrences(of: "<", with: "")
.replacingOccurrences(of: ">", with: "")

在 iOS 13 中,苹果更改了 NSData 类的描述方法的实现。所以,它返回

"{length = 32, bytes = 0x965b251c 6cb1926d e3cb366f dfb16ddd ... 5f857679 376eab7c }" // in iOS 13.

这最终破坏了许多应用程序的推送通知实现。

从现在开始,如果您需要将推送通知注册 deviceToken 转换为 Base16 编码/十六进制字符串表示形式,您应该针对 Swift 语言执行以下操作

let deviceTokenString = deviceToken.map { String(format: "%02x", $0) 
}.joined()

对于 Objective C,使用以下代码

- (NSString *)hexadecimalStringFromData:(NSData *)deviceToken {
NSUInteger dataLength = deviceToken.length;
if (dataLength == 0) {
return nil;
}

const unsigned char *dataBuffer = (const unsigned char *)deviceToken.bytes;
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
for (NSInteger index = 0; index < dataLength; ++index) {
[hexString appendFormat:@"%02x", dataBuffer[index]];
}
return [hexString copy];
}

我发现了一篇关于给定主题的综合文章 https://nshipster.com/apns-device-tokens/

关于ios - 推送通知未注册到 iOS 13 上的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57710188/

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