Apple Push Notification Device Tokens
The deviceToken parameter in the app delegate method is an opaque Data value — kind of like a really long unique phone number or email address — that the app’s push notification provider uses to route notifications through APNs to reach this particular installation of the app.
→ nshipster.com/apns-device-tokens/
In iOS 13 where a change in NSData
’s description format, from a full hexadecimal string to a summarised form—breaks push notification workflows that relied on string manipulation of deviceToken
in application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
.
Historically, developers used problematic workarounds like casting Data
to NSData
and stripping formatting, driven by the lack of Base64 support in early iOS versions. The recommended fix in iOS 13 is to convert deviceToken
to a hexadecimal string using deviceToken.map { String(format: "%02x", $0) }.joined()
, which ensures reliable encoding.
This change, while disruptive, is justified as description
was not meant for reliable data encoding, aligning with the principle that software conventions, like legal precedents, should adapt when necessary to improve functionality, such as better debugging for large data.
Category:
Tag:
Year: