When registering device to receive remote notifications, we can use device token to uniquely identify each device and even send the token to our server.
Consider the following code
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let tokenParts = deviceToken.map { data -> String in return String(format: "%02.2hhx", data) } let token = tokenParts.joined() // process token }
Here is gist for the example
// https://hashaam.com/2017/07/22/get-device-token-for-remote-push-notifications-in-swift-3/ | |
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | |
let tokenParts = deviceToken.map { data -> String in | |
return String(format: "%02.2hhx", data) | |
} | |
let token = tokenParts.joined() | |
// process token | |
} |
Source: RayWenderlich