[英]Can I use Azure CustomTemplate Push notifications with “content-available” to update iOS app in the background?
Is it possible to send an Apple-specific tag in an Azure NotificationHub notification custom template? 是否可以在Azure NotificationHub通知自定义模板中发送Apple特定的标签? I would like to send "content-available":1 to an app without switching the server to send native notifications, but I can't figure out how. 我想在不切换服务器发送本机通知的情况下向应用程序发送“内容可用”:1,但我不知道如何。
I have an iOS app using Azure Notification Hub's custom templates to send push notifications. 我有一个使用Azure Notification Hub的自定义模板发送推送通知的iOS应用。
My template works well, until now, when I have a new type of push message where I want the app to fetch info in the background. 直到现在,当我有一种新型的推送消息时,我的模板都可以正常工作,我希望该应用程序在后台获取信息。
I know how to do this on native iOS. 我知道如何在本机iOS上执行此操作。 If I subscribe to native notifications in my app and test send this as an apple native notification from Azure: 如果我在应用程序中订阅了本机通知并进行测试,则将其作为Apple本机通知从Azure发送:
{"aps":{ "content-available":1} [ other parameters...] }
Then the application (didReceiveRemoteNotification, fetchCompletionHandler) function gets called in my App delegate, and I can use the other parameters from the native notification to get the info, even if the app is closed or in the background. 然后,在我的App委托中调用了该应用程序函数(didReceiveRemoteNotification,fetchCompletionHandler),即使该应用程序处于关闭状态或在后台,我也可以使用本机通知中的其他参数来获取信息。
I have two problems trying to do this in a template though. 我在尝试在模板中执行此操作时遇到两个问题。 First, I can't figure out w here to put the content-available parameter in the custom template . 首先,我无法在此处找到将content-available参数放入自定义模板中的方式 。
Second, I can't subscribe to a template if I mention that parameter because "content-available" has a "-". 其次,如果提及该参数,我将无法订阅模板,因为“ content-available”具有“-”。
MyHub!.registerTemplateWithDeviceToken(mobiledeviceToken!, name: "none", jsonBodyTemplate: "{\"aps\": {\"alert\":\"$(message)\",\"content-available\":\"$(content-available)\"}", expiryTemplate: "", tags: tags)
I get this error: 我收到此错误:
PM</Detail></Error>" UserInfo={NSLocalizedDescription=Fail to perform registration operation. Response:<Error><Code>400</Code><Detail>Property name is content-available. Only ASCII-7 alphanumeric characters and '_' are permitted in the property name.
How can I send this parameter in a custom template, so that an iOS app can see it, and how do I subscribe to that template? 如何在自定义模板中发送此参数,以便iOS应用可以看到它,以及如何订阅该模板?
Or, do I have to switch to native notifications? 还是我必须切换到本机通知?
It looks like you should use \\"#(content_available)\\"
instead of \\"$(content-available)\\"
. 看来您应该使用\\"#(content_available)\\"
而不是\\"$(content-available)\\"
。 Notice that "-" is not alphanumeric character and also "#" will result "content-available":1
appears in actual payload while "$" would make "content-available":"1"
which you don't want. 请注意,“-”不是字母数字字符,并且“#”也将导致"content-available":1
出现在实际有效负载中,而“ $”将使"content-available":"1"
您不想要的。
Here you can find a nice article about NH templates. 在这里您可以找到有关NH模板的不错的文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.