Issues with push notification device tokens on iOS 13 (including a fix for Xamarin)

While I was trying to fix some issues with push notifications on a backend system I noticed that the device token being generated from my iPhone X running iOS 13.1 looked quite strange as it was returning something that looked like this:

{length = 32, bytes = 0x965b251c 6cb1926d e3cb366f dfb16ddd … 5f857679 376eab7c }

When I was expecting it to look more like this:

<965b251c 6cb1926d e3cb366f dfb16ddd e6b9086a 8a3cac9e 5f857679 376eab7C>


I soon found out, thanks to the articles listed below, that there is a breaking change in the way device tokens are accessed on iOS 13:

The fixes for Swift and Objective-C are provided, but what about for Xamarin? Thanks to Stack Overflow, we have the solution for that as well:

Note that this solution doesn’t take into account the formatting for iOS versions below 13, which is why I have written a code snippet that does:

public override async void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
var token = "";
/* Tokens generated on devices running iOS 13+ follow a different format which requires conversion for the backend to process them
More info:
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
byte[] result = new byte[deviceToken.Length];
Marshal.Copy(deviceToken.Bytes, result, 0, (int)deviceToken.Length);
token = BitConverter.ToString(result).Replace("", "");
token = deviceToken.Description;
token = DeviceToken.Trim('<').Trim('>');
token = DeviceToken.Replace(" ", "");
if (!string.IsNullOrWhiteSpace(token))
System.Diagnostics.Debug.WriteLine("iOS Device Token: " + token);
// Save the token using your prefered method (Xamarin.Essentials's Preferences works well)

view raw


hosted with ❤ by GitHub


There’s actually another issue that is causing problems with iOS 13 which has to do with the new apns-push-type. I will go over that in another write up, but for now I recommend reading the article from One Signal as it goes over this. As always, thanks for reading.

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s