I want to convert a device token string back into the Data format that was originally given to me through this method:
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
)
In this function I'm getting the String
from deviceToken
with
// cd414ecaf22687b31b602cec11c7c4d797ead5cfece5fc59321e7ac35e36d4c1
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
And I save this token for later use in a notification handler SDK that I'm using. The problem is that this SDK wants the Data representation of the token and not the string.
So how can i convert this string back into the Data
representation ?
What I've tried so far is
let tokenString = "cd414ecaf22687b31b602cec11c7c4d797ead5cfece5fc59321e7ac35e36d4c1"
let tokenData = Data(tokenString.utf8)
// 63643431346563616632323638376233316236303263656331316337633464373937656164356366656365356663353933323165376163333565333664346331
let decodedDataBackToString = tokenData.map { String(format: "%02.2hhx", $0) }.joined()