azure 通知中心上的 iOS13 apns-push-type 标头

cri*_*llo 1 azure push-notification azure-notificationhub ios13

从 iOS 13 和 watchOS 6 开始,Apple 要求存在用于推送通知的标头apns-push-type(此标头的值可以是alert或background)。

根据苹果文档:

此标头的值必须准确反映通知负载的内容。如果不匹配,或者所需系统上缺少标头,APN 可能会延迟通知的传递或完全丢弃它。

    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" } }
Run Code Online (Sandbox Code Playgroud)

见苹果文档

不幸的是,使用 azure 通知中心我只能定义aps内容而不能定义标题。

{ "aps": { "alert":"Alert message!", "content-available": 1 }, "CustomData": "$(CustomData)" }
Run Code Online (Sandbox Code Playgroud)

azure 通知中心如何处理它?如何指定通知的类型?

cri*_*llo 5

经过一些实验和一点点调查,这是当前 Azure 服务器的行为......

服务器检查通知的内容以推断正确的值。

如果 "content-available": 1 存在且 "alert" 缺失,则 "apns-push-type" = "background"被添加到标题中。

如果存在有效的“警报”,则将其"apns-push-type" = "alert"添加到标题中。

因此,请注意拥有有效的 APNS JSON 正文,并正确填充内容可用/警报属性。

有关 更多信息,请参阅此讨论主题

UPDATE 2019-10-15:目前后台静默通知存在一些问题见以下讨论:https : //github.com/Azure/azure-notificationhubs-dotnet/issues/96

更新 2019-11-25:服务器拒绝针对包含标头的 APNS 进行安装。现在此问题已修复,静默通知应按预期工作。