Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get iOS 13 Device Token on Xamarin.iOS
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.