4

至少在过去几天(可能更长),当我向至少 1 个测试设备发送空推送通知时,似乎什么也没发生。我几乎使用与下面发布的文章相同的 SendEmptyPushNotification 代码。

https://medium.com/@yangzhoupostbox/part-2-push-notification-for-updating-apple-pass-in-asp-net-6020768d112

我的测试设备运行的是 iOS 14.4.1。我可以手动更新 Pass,因此 WebServiceURL 可以正常工作。

我的证书今年晚些时候到期。我已经重新启动了我的设备。这一切都过去了,我没有改变任何东西。

注意:看起来 AppleDeviceLibraryIdentifier 和 ApplePushToken 会随着时间而改变。在安装通行证的 Apple 设备的整个生命周期内,这些内容应该改变还是保持不变?我想知道新的 PushToken 是否可能是问题所在。这似乎是预期的行为。设备库标识符是否随推送令牌而变化?

有谁知道可能出了什么问题?其他人有问题吗?

4

2 回答 2

3

我也是男人。让我们像 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 之后

  1. 在 Apple 迁移到新的 APNS 提供程序 API(http/2 协议)后,推送通知于 2021 年 3 月 31 日停止为开发人员工作。

  2. 要继续使用推送,请参阅此页面:https ://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/

我学到的是?

撤销与 APNS 相关的所有开发者帐户证书 制作新证书,这次在将它们安装到您的提供服务器时不要制作任何 PEM 文件。此外,请确保在2195连接到 APNS 时停止使用端口并使用443or 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, 'ssl', '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);

更新:我对 PEM 方面的看法是错误的。对于使用新的 APNs Provider API 的 APNs 连接,仍然需要创建 PEM 文件。

于 2021-04-29T01:31:24.020 回答
2

为了让它在非 .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 中。不要打开/读取文件。

希望这可以帮助!我知道这不是一个详细的解释,但希望它会对某人有所帮助。

于 2021-05-12T16:37:14.697 回答