Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created October 30, 2019 12:40
Show Gist options
  • Save SergLam/1a3616677468a966170f035c000fae60 to your computer and use it in GitHub Desktop.
Save SergLam/1a3616677468a966170f035c000fae60 to your computer and use it in GitHub Desktop.
Convert device token to string - Swift 5.1
import Foundation
// IMPORTANT: check APS environment (production or sandbox) in your app .entitlements file
extension Data {
func hexString() -> String {
return self.map{ String(format: "%02.2hhx", $0) }.joined()
}
}
// Usage:
// func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//
// let token5 = deviceToken.hexString()
// }
// Tools for push notifications testing:
// https://github.com/onmyway133/PushNotifications
// https://github.com/noodlewerk/NWPusher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment