Device token convert to String but its show on data formate.
//Remote notification Registration callback methods func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { //Call only if MoEngageAppDelegateProxyEnabled is NO MoEngage.sharedInstance().setPushToken(deviceToken) print(deviceToken) let token = String(deviceToken: deviceToken) print(token) }
Best way to convert an APNs token to String from Data.
// Define initializer convert an APNs token to String from Data----- extension String { public init(deviceToken: Data) { self = deviceToken.map { String(format: "%.2hhx", $0) }.joined() } }
Device token is of 32 Bytes. Written in hexadecimal they will take 64 digits.
Sample device token -
12b8463c1650fd2616937b913eff2fd7c84ffbc2ea741c7130374e492c6f5ad9
Thanks for reading!!
Similar solutions you may also like...
- How to remove duplicate elements from an array with Swift 5
- How to convert an APNS token to String from Data
- What is difference between enumeration and structure?
- How to store Model Class data in User Defaults in Swift?
- Adding a Custom Font to Your IOS App
- How to big numbers YAxis format values convert to Indian Numbering Format like k(thousand), L(lakh), Cr(crore), Ar(Arab) and etc.on iOS barchart Swift
- Convert number to indian rupee format in Swift 5 iOS
- How to display native iOS activity indicator in xcode Swift 5
- How to Programmatically Create an Excel Spreadsheet View iOS Swift
------------------------
0 Comments