iOS13 apns-push-type header 在 Azure 通知中心
iOS13 apns-push-type header on azure notification hub
从 iOS 13 和 watchOS 6 开始,Apple 要求存在 header apns-push-type
(此 header 的值可以是 alert
或background
) 用于推送通知。
根据 Apple 文档:
The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.
HEADERS
- END_STREAM
+ END_HEADERS
:method = POST
:scheme = https
:path = /3/device/xxxxxx
host = api.sandbox.push.apple.com
authorization = bearer xxx
apns-id = xxx-xxx-xxx
apns-push-type = alert
apns-expiration = 0
apns-priority = 10
apns-topic = com.example.MyApp
DATA
+ END_STREAM
{ "aps" : { "alert" : "Hello" } }
不幸的是,使用 azure 通知中心我只能定义 aps
内容而不能定义 header。
{ "aps": { "alert":"Alert message!", "content-available": 1 }, "CustomData": "$(CustomData)" }
Azure 通知中心如何处理它?
如何指定通知的类型?
经过一些实验和一些调查,这是当前 Azure 服务器的行为...
服务器检查通知的内容以推断出正确的值。
如果 "content-available": 1 存在且 "alert" 缺失,则将 "apns-push-type" = "background"
添加到 header。
如果存在有效的 "alert",则将 "apns-push-type" = "alert"
添加到 header。
因此请注意拥有一个有效的 APNS JSON body,并正确填充 content-available/alert 属性。
查看此discussion thread了解更多信息
2019-10-15 更新:
目前后台静默通知存在一些问题
请参阅以下讨论:
https://github.com/Azure/azure-notificationhubs-dotnet/issues/96
2019-11-25 更新:
服务器拒绝针对包含 headers 的 APNS 安装。现在这个问题已经解决,静默通知应该可以正常工作了。
此答案不准确,后台推送目前无法在 azure 上运行。 headers 需要在发送推送时包括在内,如下所示,并且集线器需要配置密钥而不是证书:
var backgroundHeaders = new Dictionary<string, string> { { "apns-push-type", "background" }, { "apns-priority", "5" } };
Dictionary<string, string> templateParams = new Dictionary<string, string>();
// populated templateParams
var notification = new TemplateNotification(templateParams);
notification.Headers = backgroundHeaders;
// the second parameter is the tag name and the template name as we have it registered from the device.
var resBack = await hubClient.SendNotificationAsync(notification, tags);
从 iOS 13 和 watchOS 6 开始,Apple 要求存在 header apns-push-type
(此 header 的值可以是 alert
或background
) 用于推送通知。
根据 Apple 文档:
The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.
HEADERS
- END_STREAM
+ END_HEADERS
:method = POST
:scheme = https
:path = /3/device/xxxxxx
host = api.sandbox.push.apple.com
authorization = bearer xxx
apns-id = xxx-xxx-xxx
apns-push-type = alert
apns-expiration = 0
apns-priority = 10
apns-topic = com.example.MyApp
DATA
+ END_STREAM
{ "aps" : { "alert" : "Hello" } }
不幸的是,使用 azure 通知中心我只能定义 aps
内容而不能定义 header。
{ "aps": { "alert":"Alert message!", "content-available": 1 }, "CustomData": "$(CustomData)" }
Azure 通知中心如何处理它? 如何指定通知的类型?
经过一些实验和一些调查,这是当前 Azure 服务器的行为...
服务器检查通知的内容以推断出正确的值。
如果 "content-available": 1 存在且 "alert" 缺失,则将 "apns-push-type" = "background"
添加到 header。
如果存在有效的 "alert",则将 "apns-push-type" = "alert"
添加到 header。
因此请注意拥有一个有效的 APNS JSON body,并正确填充 content-available/alert 属性。
查看此discussion thread了解更多信息
2019-10-15 更新: 目前后台静默通知存在一些问题 请参阅以下讨论: https://github.com/Azure/azure-notificationhubs-dotnet/issues/96
2019-11-25 更新: 服务器拒绝针对包含 headers 的 APNS 安装。现在这个问题已经解决,静默通知应该可以正常工作了。
此答案不准确,后台推送目前无法在 azure 上运行。 headers 需要在发送推送时包括在内,如下所示,并且集线器需要配置密钥而不是证书:
var backgroundHeaders = new Dictionary<string, string> { { "apns-push-type", "background" }, { "apns-priority", "5" } };
Dictionary<string, string> templateParams = new Dictionary<string, string>();
// populated templateParams
var notification = new TemplateNotification(templateParams);
notification.Headers = backgroundHeaders;
// the second parameter is the tag name and the template name as we have it registered from the device.
var resBack = await hubClient.SendNotificationAsync(notification, tags);