当前位置: 动力学知识库 > 问答 > 编程问答 >

swift - Azure notifications hub can't register template with content-available

问题描述:

I am trying to register a template for Azure Notifications Hub for iOS with content-available field in aps and I'm having some issues regarding this. When I register a template with the following format it works:

"{\"aps\" : {\"alert\":\"$(message)\" }, \"payload\": { \"type\" : \"$(type)\", \"startDate\" : \"$(startDate)\", \"id\" : \"$(id)\"} }"

However, when I try to add content-available field, since I want to be able to send silent notifications I get an error from Azure saying it's bad request:

"{\"aps\" : {\"alert\":\"$(message)\", \"content-available\": \"$(content-available)\", \"sound\":\"\" }, \"payload\": { \"type\" : \"$(type)\", \"startDate\" : \"$(startDate)\", \"id\" : \"$(id)\"} }"

When I change "$" notation to "#" and "-" to "_" I can register sucessfully however, when I try to send notification I get an error on Azure portal saying notification payload is invalid:

"{\"aps\" : {\"alert\":\"$(message)\", \"content-available\": \"#(content_available)\", \"sound\":\"\" }, \"payload\": { \"type\" : \"$(type)\", \"startDate\" : \"$(startDate)\", \"sleeperId\" : \"$(sleeperId)\"} }"

I understand that this problem has something do to with the fact that "content-available" has "-" which Azure cannot parse.

网友答案:

I managed to solve it, instead of 1 or 0 you should put true/false. So the code for content-available in the template should look like this:

\"content-available\": \"#(content_available)\"

And when sending the notification put

content-available: true

This eliminates notification payload error and you receive silent notification in the background. Also make sure that alert and sound are empty strings.

分享给朋友:
您可能感兴趣的文章:
随机阅读: