推送通知未在iOS 13上注册到应用程序 [英] Push notification not register to the app on iOS 13

查看:42
本文介绍了推送通知未在iOS 13上注册到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了我的应用程序,并在 didRegisterForRemoteNotificationsWithDeviceToken 中放置了一个断点,但未触发.它可以在其他版本的iOS上正常运行.

I build my app and I put a breakpoint in didRegisterForRemoteNotificationsWithDeviceToken but it's not triggered. It works fine on other versions of iOS.

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

Is this a bug in iOS 13 or did I miss something new in iOS 13?

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

I use Xcode Beta 6 and iOS 13 beta 8.

推荐答案

上述问题也可以通过重新连接wifi或在wifi和蜂窝数据之间切换来解决.

The aforesaid problem could also be resolved by reconnecting wifi or switching between wifi and cellular data.

此外,随着iOS 13中的更改,推送通知的实现受到影响.

Moreover, following changes in iOS 13 affected push notification implementation.

在iOS 13之前,我们很多人曾经做过

Prior to iOS 13 many of us used to do

(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类的描述方法的实现.因此,它返回

In iOS 13 apple has changed the implementation of its description method for NSData class. So, it returns

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

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

Which ended up breaking push notifications implementation for many applications.

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

From now on, if you need to convert your push notification registration deviceToken into a Base16-encoded / hexadecimal string representation, you should do the following for Swift language

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

对于目标C,请使用以下代码

For Objective C, use following code

- (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/

I came across a comprehensive article on the given topic https://nshipster.com/apns-device-tokens/

这篇关于推送通知未在iOS 13上注册到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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