With XCode 11 I am no longer able to view the full value for a push token. Here's some example code to illustrate:
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType)
{
var method1 = NSString(format: "%@", credentials.token as CVarArg) as String
print("method1: \(method1)")
method1 = method1.replacingOccurrences(of: " ", with: "")
method1 = method1.replacingOccurrences(of: "<", with: "")
method1 = method1.replacingOccurrences(of: ">", with: "")
print("method1 again: \(method1)")
let method2 = String(decoding: credentials.token, as: UTF8.self)
print("method2: \(String(describing: method2))")
let method3 = credentials.token.description as String
print("method3: \(method3)")
However when the above code is run with Xcode 11, this is the output:
method1: {length = 32, bytes = 0x5b3f44e0 6d2c5ee5 5252d3db f5bb915b ... 12844aeb 13259e7e }
method1 again: {length=32,bytes=0x5b3f44e06d2c5ee55252d3dbf5bb915b...12844aeb13259e7e}
method2: [?D�m,^�RR�����[����>��J�%�~
method3: 32 bytes
As viewing the variables in Xcode:
In previous versions of Xcode, method1 would be logged/viewable as something like this:
44154da73234500153106883ffc1071fa59c0d24f1a1d29ea70871e5aa8dbb41
But now its this:
0x5b3f44e06d2c5ee55252d3dbf5bb915b...12844aeb13259e7e
There is ... in the middle of it.
How can I just log/interactively view the contents of credentials.token with Xcode 11?
I want to copy/paste the value into a php script to manually send push message to the app for testing purposes.
This
let tokenParts = credentials.token.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
Maybe try printing out each character--rather than the whole string:
let str = "44154da73234500153106883ffc1071fa59c0d24f1a1d29ea70871e5aa8dbb41"
let tokenData = Data(str.utf8)
let tokenStr = String(decoding: tokenData, as: UTF8.self)
//Supposedly, that is a failable String initializer and therefore it returns an optional type.
print(str)
if let tokenStr = tokenStr {
for c in tokenStr {
print(c, terminator: "")
}
}
output:
44154da73234500153106883ffc1071fa59c0d24f1a1d29ea70871e5aa8dbb41
44154da73234500153106883ffc1071fa59c0d24f1a1d29ea70871e5aa8dbb41
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With