Jacob Hughes
04/26/2023, 2:28 PMNSData
) to a string in Kotlin
This is what I have done previously
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
var tokenString = ""
for i in 0..<deviceToken.length {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}
print("tokenString: \(tokenString)")
When trying to do in KMM I run into issues
KMM
actual typealias PushToken = NSData
fun PushToken.toString(): String {
// Unsure of what to do here
}
Has anyone done anything similar?Anonymike
04/26/2023, 6:09 PMdeviceToken.map { String(format: "%02x", $0) }.joined()
That gives us a human readable string version of the device token, which we send to servers.