如何解决SendEmptyPushNotification 到 gateway.push.apple.com 不再工作
至少在过去几天(可能更长),当我向至少 1 个测试设备发送空推送通知时,似乎没有任何反应。我几乎使用与下面发布的文章相同的 SendEmptyPushNotification 代码。
https://www.baeldung.com/jvm-compressed-oops
我的测试设备运行的是 iOS 14.4.1。我可以手动更新 Pass,因此 WebServiceURL 可以正常工作。
我的证书将于今年晚些时候到期。我已经重新启动了我的设备。这一切都过去了,我没有改变任何东西。
注意:看起来 AppleDeviceLibraryIdentifier 和 ApplePushToken 会随着时间发生变化。在安装了通行证的 Apple 设备的整个生命周期中,这些应该改变还是保持不变?我想知道新的 PushToken 是否可能是问题所在。这似乎是预期的行为。 https://medium.com/@yangzhoupostbox/part-2-push-notification-for-updating-apple-pass-in-asp-net-6020768d112
有谁知道什么可能是错的?其他人有问题吗?
解决方法
我也是。让我们像 Apex Legends 一样一起解决这个问题。
我已向 Apple 提交了 TSI。他们在 2 月 10 日发送了一封电子邮件说:
从 2021 年 3 月 29 日起,与 Apple 推送通知服务的基于令牌和证书的 HTTP/2 连接必须包含新的根证书 (AAACertificateServices 5/12/2020),以取代旧的 GeoTrust Global CA 根证书。为确保无缝过渡并避免推送通知传送失败,请在 3 月 29 日之前验证 HTTP/2 接口的新旧根证书都包含在每个通知服务器的信任存储中。
请注意,Apple 向您颁发的 Apple Push Notification 服务 SSL 提供商证书此时无需更新。
了解有关连接到 APN 的更多信息。
如果您有任何问题,请联系我们。
最好的问候, Apple 开发者关系
更新 - 5 月 3 日星期一,在向 Apple Dev 提交 TSI 后
-
在 Apple 迁移到新的 APNS 提供程序 API(http/2 协议)后,推送通知于 2021 年 3 月 31 日停止为开发者工作。
我学到了什么?
撤销所有与APNS相关的开发者账号证书
制作新证书,这次在将它们安装到您的提供服务器时不要制作任何 PEM 文件。此外,确保在连接到 APNS 时停止使用端口 2195
,并使用 443
或 2197
。
好消息?新的 APNS 提供程序 API 仍然与 Objective C 兼容!
?
<?php
// Put your device token here (without spaces):
$deviceToken = '09a0c8ff92b3621c5f5032c1fa031f2851d01dd99beaf1446c281c5458fe2ffd';
// Put your private key's passphrase here:
$passphrase = 'pushchat';
// Put your alert message here:
$message = 'Hello!';
$ctx = stream_context_create();
stream_context_set_option($ctx,'ssl','local_cert','ck.pem');
stream_context_set_option($ctx,'passphrase',$passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT,$ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n',32) . pack('H*',$deviceToken) . pack('n',strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp,$msg,strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
,
为了让它在非 .Net Core 解决方案中工作,我必须从 Asp.net 4.6.1 升级到 4.7.2。然后我在我的项目中创建了一个名为 AppleAPNS 的文件夹。我添加了在这里找到的所有文件。
注意:我必须升级到 4.7.2 才能让项目识别在 AppleCryptoHelper 文件中找到的 CreateFromValue。
https://github.com/andrei-m-code/net-core-push-notifications/tree/master/CorePush/Apple
然后我将这里找到的文件添加到 AppleAPNS 文件夹中。
https://github.com/andrei-m-code/net-core-push-notifications/tree/master/CorePush/Utils
然后我将 WinHttpHandler 项目和这个助手一起添加到我的 AppleAPNS 文件夹中。这将确保您使用支持 2.0 的 HTTP 客户端调用 APNS。
public class Http2CustomHandler : WinHttpHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,System.Threading.CancellationToken cancellationToken)
{
request.Version = new Version("2.0");
return base.SendAsync(request,cancellationToken);
}
}
接下来,添加这里找到的 AppleNotification 类,并使用 program.cs 文件中的调用方法。
https://github.com/andrei-m-code/net-core-push-notifications/tree/master/CorePush.Tester
要使用 Http2CustomHandler,请进行这些更改。
ApnSender.cs
//private readonly HttpClient http;
private readonly HttpClient http = new HttpClient(new Http2CustomHandler());
在您的调用方法中进行此更改。
//private static readonly HttpClient http = new HttpClient();
private static readonly HttpClient http = new HttpClient(new Http2CustomHandler());
最后,进行此更改以发送空推送通知以更新通行证。
ApnSender.cs
//var json = JsonHelper.Serialize(notification);
var json = "{\"aps\":\"\"}";
注意:将 p8 文件的内容作为字符串复制到调用方法中的 apnP8PrivateKey 中。不要打开/读取文件。
希望这有帮助!我知道这不是一个详细的解释,但希望它会帮助某人。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。