简体   繁体   English

我可以使用带有“内容可用”的Azure CustomTemplate Push通知在后台更新iOS应用吗?

[英]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.

相关问题 在iOS 7推送通知中正确使用“内容可用” - Proper use of “content-available” in iOS 7 Push Notifications 我可以使用iOS推送通知进行应用实时内容更新吗? - Can I use iOS push notifications for app realtime content update? 注册仅适用于内容的推送通知 - Register for content-available push notifications only iOS 7.1是否打破了针对非报亭应用的内容可用(又称无声)推送通知? - Did iOS 7.1 break content-available (aka silent) push notifications for non-newsstand apps? 使用内容可用的推送通知来更新iOS应用 - Using content available push notifications to update iOS app Azure服务器脚本:将通知推送到iOS设备:如何将可用内容设置为1? - Azure Server Script: Push Notification to iOS device: How to set content-available to 1? 当“内容可用”时,iOS远程通知不起作用:1 - iOS Remote Notifications not working when “content-available”: 1 禁用了推送通知的用户是否可以使用具有内容可用的推送通知? - Do Push Notifications with content-available work for users that have disabled Push Notifications? 内容可用于非静音推送吗? - can content-available be used in a non-silent push? 推送通知 Json 中“内容可用”的目的是什么? - The purpose of “Content-available” in Push Notification Json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM