How to get the device token from new xCode 8, Swift 3 in iOS 10?
Here is the code to register notification:
<
One line:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let apnsDeviceToken = deviceToken.map {String(format: "%02.2hhx", $0)}.joined()
}
From this tutorial.
Or a modular/encapsulated/OOP way:
extension Data {
var string: String {
return map {String(format: "%02.2hhx", $0)}.joined()
}
}
Then you can do this:
let token = deviceToken.string