How to get device token in iOS 13 with Xamarin?

Here's another way to do:

var bytes = deviceToken.ToArray<byte>();
var hexStringArray = bytes.Select(b => b.ToString("x2")).ToArray();    
var token = string.Join(string.Empty, hexStringArray);

The code above is based on a post by NSHipster as I described in my own post https://medium.com/@kevinle/correctly-capture-ios-13-device-token-in-xamarin-3d0fa390b71b


Looks like I found the answer myself:

byte[] result = new byte[deviceToken.Length];
Marshal.Copy(deviceToken.Bytes, result, 0, (int) deviceToken.Length);
var token = BitConverter.ToString(result).Replace("-", "");

Using this code I was able to get a device token and send a notification.


You can use a more simplified version:

var bytes = deviceToken.ToArray();
var token = BitConverter.ToString(bytes).Replace("-", "");