我使用的是 PushSharp 2.1.2 版。该应用程序是 .NET 4.5.1(尽管我也尝试过针对 .NET 4.5 和 .NET 4)
我正在尝试但没有成功通过沙盒 Apple APNS 发送推送消息。
我正在使用Ray Wenderlich 的演练中提供的 PHP 脚本成功发送消息,使用相同的证书并发送到与我的 PushSharp 应用程序相同的设备 ID。
我已经通过从钥匙链中将完成的证书导出为 p12 进行了测试。导出完成的证书和密钥。导出私钥。也可以通过这里使用的方法。当我将证书和密钥结合起来用于 PHP 脚本时,我没有任何问题。
我已经将 p12 证书导入到我测试过的机器上——似乎没有什么区别。
在将苹果推送服务注册到推送代理时,我尝试更改 IsProduction 标志。将其设置为生产时没有错误(即使这是一个沙盒证书),但在这种情况下它显然也无法进入设备。
我的所有消息都不会通过,都会出现如下所示的服务异常:
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted
--- End of inner exception stack trace ---
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at PushSharp.Apple.FeedbackService.Run(ApplePushChannelSettings settings, CancellationToken cancelToken)
at PushSharp.Apple.ApplePushService.<>c__DisplayClass4.<.ctor>b__1(Object state)
这基本上是我的代码的样子:
var push = new PushBroker();
// register event handlers for channel create/destroy/exception, notificationrequeue, serviceexception, notification sent
var appleCert = File.ReadAllBytes(ConfigurationManager.AppSettings["CertAddress"]);
push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, ConfigurationManager.AppSettings["CertPassword"]));
var pn = new AppleNotification().ForDeviceToken(item.SendToDeviceIdentifier).WithAlert(item.AlertMessage).WithBadge(item.Badges);
push.QueueNotification(pn);
我调用了通道启动事件,然后调用了服务异常。
一些相关问题提到此错误可能与防火墙问题有关 - 我已经在 2 个能够发送推送通知的不同网络中测试了我的应用程序(其中 1 个当前正在使用 PushSharp 应用程序)。
任何见解将不胜感激。