如何发送静默的推送通知有效负载
我只想知道如何确定对无声推送执行的操作:
I just want to know how I can determine what action to do on a silent push:
这是我发送给客户端的aps
:
This is the aps
that I sent to the client:
"aps": {
"content-available": 1
}
现在的问题是,当我添加type: "Order_Update"
以确定静默推送是为了让订单更新"显示警报通知时.
My problem now is when I add type: "Order_Update"
to determine that the silent push is for the Order Update to display an alert notification.
有一些选择!让我们花点时间了解所有不同的有效负载及其用法.
There are a few options for it! Let's take a small ride to understand all the different payloads and their usage.
简单有效载荷
显示在通知中心中:是
唤醒应用程序以执行后台任务:否
Wakes app to perform background task : No
{
"aps" : {
"alert" : "You received simple notification!",
"badge" : 1,
"sound" : "default"
}
}
带有自定义通知声音的负载
显示在通知中心中:是
唤醒应用程序以执行后台任务:否
Wakes app to perform background task : No
Step 1
:在应用程序包中添加自定义通知声音文件(仅.wav或.aiff扩展名,例如notification.wav).
Step 1
: Add custom notification sound file (.wav or .aiff extensions only. e.g. notification.wav) in your app bundle.
Step 2
:如下所示配置有效载荷以播放自定义声音
Step 2
: Configure your payload as shown below to play your custom sound
{
"aps" : {
"alert" : "It's a custom notification sound!",
"badge" : 1,
"sound" : "notification.wav"
}
}
自定义有效负载通知
显示在通知中心中:是
唤醒应用程序以执行后台任务:否
Wakes app to perform background task : No
{
"aps" : {
"alert" : "It's a notification with custom payload!",
"badge" : 1,
"content-available" : 0
},
"data" :{
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
}
在这里data
词典可保存您想要的自定义信息.它还将显示为带有警报消息这是具有自定义有效负载的通知!"的正常通知.
Here the data
dictionary holds custom information whatever you want. It will also display as normal notification with the alert message "It's a notification with custom payload!".
正常静默通知
它不会在通知栏上显示警报;它只会通知您的应用程序有一些新数据可用,提示应用程序获取新内容.
It will not a show an alert as a notification bar; it will only notify your app that there is some new data available, prompting the app to fetch new content.
显示在通知中心:否
唤醒应用以执行后台任务:是
Awake app to perform background task : Yes
{
"content-available" : 1
}
具有自定义有效负载的静音通知
在这里,魔术可以显示通知警报,并在后台唤醒您的应用以执行任务! (注意:仅当它在后台运行并且未被用户明确杀死时才如此.)
只需在有效负载中添加额外的参数"content-available" : 1
.
Here comes the magic to show a notification alert as well awake your app in background for a task! (Note: only if it's running in background and has not been killed explicitly by the user.)
Just add the extra parameter "content-available" : 1
in your payload.
显示在通知中心中:是
唤醒应用程序以执行后台任务:是
Wakes app to perform background task : Yes
{
"aps" : {
"alert" : "Notification with custom payload!",
"badge" : 1,
"content-available" : 1
},
"data" :{
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
}
}
根据您的应用程序要求使用任何这些有效负载.对于background app refresh
,请参考
Use any of these payloads according to your app requirements. For background app refresh
refer to Apple's documentation. I hope this gives you all the necessary information. Happy coding :)