问题描述
如果在同一有效负载中有body和loc-args和loc-key,以下有效负载通知会引起任何问题吗?
Would the following payload notification cause any problems if you have body and loc-args and loc-key in the same payload?
{"aps":{"alert":{"body" : "Bob wants to play poker", "loc-key":"general","loc-args":["Test DEFAULT."]},"badge":1,"sound":"default"}}
我这样设置的原因.是我不确定在应用程序期间是否可以处理仅包含主体的通知,因此它将在本地化字符串中使用本地化loc-args和以下键值:
The reason I have it set up like this. Is that I am not sure if the notification to just have a body in would be handle during the app, so it would use the localized loc-args in with the following key-valus in the localizable string:
"general"="%@";
推荐答案
有两个选项可本地化推送通知中嵌入的警报消息.一种是在服务器上本地化,然后将本地化的消息作为alert
键的字符串值发送.例如:
There are two options to localize an alert message embedded in a push notification. One is to localize on the server and send the localized message as a string value of the alert
key. Eg:
{"alert": "A localized sentence."}
(可选)如果您还希望设置启动图像和/或使警报的查看按钮读取查看"以外的内容,则可以用字典替换alert
的字符串值.在这种情况下,字符串值应为字典中body
的值.例如:
Optionally, if you want to also set the launch image and/or have the view button of the alert read something other than 'View', you would replace the string value of alert
with a dictionary. In this case the string value should be the value of body
in the dictionary. Eg:
{'alert':{'body: "A localized sentence.", action-loc-key: "...", launch-image: "..."'}}
{'alert':{'body: "A localized sentence.", action-loc-key: "...", launch-image: "..."'}}
文档警告说,如果字典中只有body
键,请不要使用字典.而是将body
的值设置为alert
的字符串值.
The docs warn that if you only have the body
key in the dictionary, don't use a dictionary. Instead set the value of body
as the string value of alert
.
另一种选择是使用loc-key
和loc-args
对,并在设备上进行本地化.
The other option is to use the loc-key
, loc-args
pair and have the localization take place on the device.
尽管我还没有验证alert
词典中是否同时存在body
和loc-key
,但哪个iOS默认为默认设置,但我猜它会选择其中一个而忽略另一个.有权访问有效的推送通知开发者设置的人可以验证哪个.
Although I have not verified which one iOS defaults to if both body
and loc-key
are present in the alert
dictionary, I guess it will pick one and ignore the other. Someone with access to a working push notification dev setup could verify which one.
最终,可以从文档,应以互斥或关联关系使用body
和loc-key
.一个或另一个,但不能两者都选.
Ultimately, one can infer from the docs that body
and loc-key
should be used in an exclusive or relationship. Either one or the other, but not both.
这篇关于具有相同通知有效负载中的body和loc-args的以下结构是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!