首页 > 解决方案 > 为什么 iOS 设备可能不会收到来自 Azure 推送通知中心的推送通知?

问题描述

问题

我想在 iOS 设备上接收推送通知,这些是从我的 web api 发送的,但从未收到推送通知。

从 API 发送的所有通知都在 Azure 推送通知指标中显示为成功发送,但设备未收到。

但是,如果从 Azure 推送通知中心发送推送通知,通过测试发送,通知将成功发送和接收。

配置:

Web API 配置:
.NET Core 2.2 Web api
Nuget 从 Web api 发送推送通知:Microsoft.Azure.NotificationHubs
所有设备都注册为来自 Web api 端点的安装。

await _hubClient.CreateOrUpdateInstallationAsync(new Installation()
{
    Tags = installation.Tags,
    Platform = NotificationPlatform.Apns,
    PushChannel = installation.PushChannel,
    InstallationId = Guid.NewGuid().ToString()
});

本机方法用于发送推送通知。

var headers = new Dictionary<string, string>
{
    { "apns-push-type", "alert" },
    { "apns-priority", "5" }
};
var message = "{\"Aps\":{\"Alert\":\"Notification Hub test notification\"}}";
var tagExpression = newNotification.Tags.Aggregate((first, second) => $"{first} || {second}");
var notification = new AppleNotification(message, headers);
outcome = await _hubClient.SendNotificationAsync(notification, tagExpression, CancellationToken.None);

我也尝试过以下方法,但结果相同:

await _hubClient.SendAppleNativeNotificationAsync(newNotification.Content, tagExpression);

Azure:
Azure Notification Hub Apple (APNS) 为生产环境配置了基于令牌的身份验证。

另外,我试过:

  1. Azure 推送通知中心的基于证书的身份验证;
  2. enableTestSend以获得更好的调试体验。结果通知结果为“成功”;
  3. 将 Azure 推送通知计划增加到 S1,以获得更好的调试体验。结果通知结果也是“成功”;
  4. 重新创建推送通知中心;
  5. 移除所有现有装置;
  6. 在 5 个不同的设备上完成了测试。

问题:

  1. 有没有办法在 Azure 通知中心之外调试未传递的推送通知?
  2. 在这种情况下,什么会导致推送通知无法发送?

标签: azureasp.net-corepush-notificationapple-push-notificationsazure-notificationhub

解决方案


好的,我的问题很快就解决了:)

万一有人想知道,APNS 模板中有错字。这不是骆驼案。
错误的:

"{\"Aps\":{\"Alert\":\"Notification Hub test notification\"}}"

好的:

"{\"aps\":{\"alert\":\"Notification Hub test notification\"}}"

推荐阅读