how to validate Apple APN device token - WCF .NET

2019-04-12 12:13发布

问题:

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,

回答1:

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.



回答2:

This is the little irrelevant answer, but recently i came across this question,
as my problem was that i have long list of Notification Token and in that some of them are invalide.
So i need to filter them, but there is not easy way for that but there is 1 app that i use to send/test notification certificate,
Knuff : https://github.com/KnuffApp/Knuff/releases

In that if you give it wrong notification token than it will display error like this,

So that way anyone can validate the push notification token.
Hope it will help user like me.