简体   繁体   中英

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? 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.

I have an iOS app using Azure Notification Hub's custom templates to send push notifications.

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. If I subscribe to native notifications in my app and test send this as an apple native notification from 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.

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 .

Second, I can't subscribe to a template if I mention that parameter because "content-available" has a "-".

 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?

Or, do I have to switch to native notifications?

It looks like you should use \\"#(content_available)\\" instead of \\"$(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.

Here you can find a nice article about NH templates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM