I tried save devicetoken into userDefaults for later use.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print(deviceToken) // value print as 32 bytes
let encodedData: Data = NSKeyedArchiver.archivedData(withRootObject: deviceToken)
UserDefaults.standard.set(encodedData , forKey: "deviceToken")
let decoded = UserDefaults.standard.data(forKey: "deviceToken")
print(decoded) // value print as 172 bytes
}
i don't know whether the printing value is correct or not. how to verify it? or if my storing mechanism is wrong. how can i save data for later usage?
Encoding
DatatoDatais redundant, just save the token directlyand you can display the bytes with
What use? The server which sends the notification needs to maintain the token but not the client.