I build my app and I put a breakpoint in didRegisterForRemoteNotificationsWithDeviceToken but it\'s not triggered.
It works fine on other versions of iOS.
The aforesaid problem could also be resolved by reconnecting wifi or switching between wifi and cellular data.
Moreover, following changes in iOS 13 affected push notification implementation.
Prior to iOS 13 many of us used to do
(deviceToken as NSData).description
// Used to return as follows
"<965b251c 6cb1926d e3cb366f dfb16ffffd 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: "")
In iOS 13 apple has changed the implementation of its description method for NSData class. So, it returns
"{length = 32, bytes = 0x965b251c 6cb1926d e3cb366f dfb16ffffd ... 5f857679 376eab7c }" // in iOS 13.
Which ended up breaking push notifications implementation for many applications.
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()
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];
}
I came across a comprehensive article on the given topic https://nshipster.com/apns-device-tokens/