Swift - Override push tokens

PHOTO EMBED

Thu Feb 25 2021 09:56:10 GMT+0000 (UTC)

Saved by @argenisferrer #swift

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()
    }
content_copyCOPY