private func deviceTokenDataToString(_ deviceToken: Data) -> String {
let tokenChars = (deviceToken as NSData).bytes.assumingMemoryBound(to: CChar.self)
var tokenString = ""
for i in 0..<deviceToken.count {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}
return tokenString
}
func updateDeviceToken() {
guard let deviceToken: Data = dataStorageService.value(for: .pushDeviceToken),
deviceToken.isEmpty == false else {
return
}
let stringPushToken = deviceTokenDataToString(deviceToken)
mixpanel?.track(event: "Push Token Updated", properties: ["token": stringPushToken])
peopleObject?.people.set(properties: ["$ios_devices": [stringPushToken]]
mixpanel?.flush()
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter