我正在使用PushSharp的版本2.1.2。该应用程序是.NET 4.5.1(尽管我也尝试过针对.NET 4.5和.NET 4)。
我正在尝试但未能通过sandbox Apple APNS发送推送消息。
我成功地使用提供的PHP脚本发送消息,该脚本在Ray Wenderlich的演练中这里使用相同的证书并发送到与我的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);
我已经收到频道开启事件,但是接着出现了服务异常。
一些相关的问题提到这个错误可能与防火墙有关 - 我已经在能够发送推送通知的两个不同网络中测试了我的应用程序(其中一个当前正在使用PushSharp应用程序)。
非常感谢您的任何见解。