DEV Community

Correctly capture iOS 13 Device Token in Xamarin

Kevin Le on October 24, 2019

Cross posted on Medium Capturing the Device Tokens is necessary for push notification to work. A Device Token is nothing but an ID that uniquely i...
Collapse
 
aledut profile image
aledut

Hello, Kevin, great article!

I have another question though.
I do need to recreate the NSData to update tags on azure. Before ios 13 i would do just this:
NSData nsData = new NSData(DeviceToken, NSDataBase64DecodingOptions.None);

that doesnt seems to work on ios13 since the NSData has a different structure, would you know how to do that too?

Thanks a lot!

Collapse
 
ksbecker profile image
ksbecker

What happens if you fail to capture the token on RegisteredForRemoteNotifications? Is there a way to get to token later? Or maybe the person originally denied push but later went into Settings and enabled it there. How do you know that happened and how do you get the token then?

Collapse
 
codeprototype profile image
Kevin Le

That's an interesting scenario: user disable push notif, launch app, then user enable push. Question is in between, what does iOS pass when it calls RegisteredForRemoteNotifications. We will need to test. But that's common regardless of app being in Xamarin, Obj-C, Swift, etc.

Collapse
 
incidentist profile image
Dan Kurtz

Thank you for this excellent explanation of the problem and a succinct C# solution. It helped me a lot.

Collapse
 
shipitfaster profile image
David

Got bit by this as well after upgrading to iOS 13.

Collapse
 
greatvova profile image
greatvova

Great article. Thanks a lot.

Collapse
 
ederbond profile image
Eder Cardoso

Thanks a Lot Kevin.