azure - 为什么 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) 为生产环境配置了基于令牌的身份验证。
另外,我试过:
- Azure 推送通知中心的基于证书的身份验证;
- enableTestSend以获得更好的调试体验。结果通知结果为“成功”;
- 将 Azure 推送通知计划增加到 S1,以获得更好的调试体验。结果通知结果也是“成功”;
- 重新创建推送通知中心;
- 移除所有现有装置;
- 在 5 个不同的设备上完成了测试。
问题:
- 有没有办法在 Azure 通知中心之外调试未传递的推送通知?
- 在这种情况下,什么会导致推送通知无法发送?
解决方案
好的,我的问题很快就解决了:)
万一有人想知道,APNS 模板中有错字。这不是骆驼案。
错误的:
"{\"Aps\":{\"Alert\":\"Notification Hub test notification\"}}"
好的:
"{\"aps\":{\"alert\":\"Notification Hub test notification\"}}"
推荐阅读
- angular - 如何以角度将对象从服务返回到组件
- vue-chartjs - 如何始终显示工具提示?我正在使用 vue-chartjs v3.4
- tensorflow - “numpy.dtype”对象没有属性“base_dtype”
- mongodb - 如何用一个数组聚合多个文档?
- php - sUrl 和 fUrl 应该是什么 - PayU Money iOS 集成
- c# - 使用 C# 解析 Debian 软件包版本
- angular - 以角度检查新对象并将其推送到表格组件
- javascript - 获取字符串中的数组 [javascript]
- r - 需要替代 r 中的嵌套循环
- assembly - 文件创建权限问题汇编语言