Anamika
Anamika

Reputation: 56

ios 13 push notification device token

I have been reading everywhere that ios 13 is now returning device token in a separate format and if not handled our notification might break. I am able to see lots of wrong format device token getting saved in my database. eg: {length=32,bytes=0x64......0c6f} When I am trying to debug, I can see that my ios 13 device is sending correct device token to my database without making any change to handle the new way. Is there any scenario it might send previous format device token for iOS 13?

Upvotes: 1

Views: 508

Answers (2)

Nick
Nick

Reputation: 875

For iOS 13 try this:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
    let token = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
    print(token)
}

Upvotes: 1

Anshul
Anshul

Reputation: 4550

This is the way write extension of data or use directly

extension Data {
    var hexString: String {
        let hexString = map { String(format: "%02.2hhx", $0) }.joined()
        return hexString
    }
}


     func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
            let devicetoken= deviceToken.hexString
            print(devicetoken)
}

Upvotes: 0

Related Questions