how to validate Apple APN device token - WCF .NET

user3329344 picture user3329344 · Feb 19, 2014 · Viewed 11.4k times · Source

I am building a WCF REST web service that is called by the mobile app to insert the Apple device Token into the database. I would like to validate a device token before inserting into the database. Is there anyway to validate a device token to know if it is valid??

I have searched around the forum and could not find any sample code (in .NET) to do this, there were recommendations that I should use the Apple FeedBack service but how do I do that in .NET??

Could anyone please provide me a piece of sample code to validate an Apple Device Token in .NET.

Many thanks,

Answer

Eran picture Eran · Feb 19, 2014

You can't validate the device token. The only thing you can validate before inserting the token to your DB is that its length is 32 bytes (in binary representation) or 64 Hexadecimal characters (in a String representation).

Beyond that, you should check the responses from Apple to see if you get an InvalidToken error response. If you do, you know the device token sent with the message that causes the error is invalid.

The Feedback Service does not return invalid tokens. It returns valid tokens of devices that uninstalled your app.

I can't give you any C# code, but PushSharp should support calling the Feedback Service and reading error responses from Apple.