how to validate Apple APN device token - WCF .NET

杀马特。学长 韩版系。学妹 提交于 2019-12-06 08:46:37

问题


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.



来源:https://stackoverflow.com/questions/21888440/how-to-validate-apple-apn-device-token-wcf-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!