Swift 3 - device tokens are now being parsed as '32BYTES' Swift 3 - device tokens are now being parsed as '32BYTES' ios ios

Swift 3 - device tokens are now being parsed as '32BYTES'


func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {    let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()    print(token)}


I had the same problem. This is my solution:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {    var token = ""    for i in 0..<deviceToken.count {        token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])    }    print(token)}


Here is my Swift 3 extension to get a base-16 encoded hex string:

extension Data {    var hexString: String {        return map { String(format: "%02.2hhx", arguments: [$0]) }.joined()    }}