推送尖兵(PushSharp)苹果版 - 收到的消息不符合预期或格式错误。

12

我正在使用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应用程序)。

非常感谢您的任何见解。


我刚刚发布了一个答案,希望能有所帮助。 http://stackoverflow.com/questions/23116726/pushsharp-notifications-to-ios-are-not-reaching-device/23121205#23121205 - dichen
2个回答

30

我们使用已废弃的APNS-Sharp库(PushSharp的前身),遇到了同样的问题。我根据我的测试为APNS-Sharp提交了一个拉取请求,以修复这个问题。

修改是更改ApplePushChannel.cs中的内容。

stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);                   

to

的翻译是“致”。
stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Tls, false);

我没有找到关于这个问题的确认,但看起来沙箱APNS不再支持SSL3协议。就像其他报告该问题的人一样,我的生产APNS通知仍在工作。

您可以在此处找到拉取请求:

https://github.com/Redth/PushSharp/pull/369/files

更新

苹果开发者网站上有一个关于此主题的线程:

https://devforums.apple.com/thread/224320?tstart=0

然而,一些人也在这个线程或github线程中。因此,这些信息是有偏见的。我在苹果公司认识的人说:

虽然还没有官方文件,但似乎APNS正在向TLS转移而不是SSL(仅基于看到这种变化-我没有听到任何正式消息)。


1
谢谢!你的拉取请求正是我所做的更改,现在它可以工作了。 - bean
我尝试跟随链接到苹果开发者论坛,以解释从SSL到TLS的重点,但它只是转到了我的会员中心主页。 - Michael Kniskern
我也没有运气。我从Github上下载了Moon-APNS的源代码https://github.com/arashnorouzi/Moon-APNS,尝试自己制作通知应用程序,并在该解决方案中的同一行代码处遇到了相同的错误。我尝试了`System.Security.Authentication.SslProtocols.Tls`、`System.Security.Authentication.SslProtocols.Ssl3`和`System.Security.Authentication.SslProtocols.Default`。 - Michael Kniskern
我今天遇到了同样的问题,通过上面的修复方法解决了;但是我觉得这很奇怪。有人知道这个问题是否已经在某个地方记录过吗? - Codor
没错,从SSL3到TLS,完美解决了这个问题。 - Nicholas Petersen
显示剩余3条评论

2
如果您在运行Windows Server 2003上遇到问题(我知道,我知道),即使您实施了修复程序,仍然会出现奇怪的错误,因此您需要运行此补丁。 我花了几个小时想知道为什么我的2008服务器可以工作而我的2003服务器不行。 http://support.microsoft.com/kb/948963

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接