PushSharp Apns通知错误:' ConnectionError'

时间:2016-06-30 08:01:40

标签: ios asp.net-mvc-4 push-notification pushsharp apn

我使用的是PushSharp 4.0.10,MVC 4和c#
在Apns代理的OnNotificationFailed事件中,我得到ConnectionError异常 更改证书(.p12)文件后突然发生此异常;在这次改变之前它运作良好 请告知如何解决此错误。

var certificate = System.IO.File.ReadAllBytes(System.Web.Hosting.HostingEnvironment.MapPath("~/Content/Mobile/consumer_dev.p12"));

var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, certificate, "", true);

var apnsBroker = new ApnsServiceBroker(config);

apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
    aggregateEx.Handle (ex => {
        if (ex is ApnsNotificationException) {
            var notificationException = (ApnsNotificationException)ex;
            var apnsNotification = notificationException.Notification;
            var statusCode = notificationException.ErrorStatusCode;

            Debug.WriteLine(apnsNotification.Identifier + ", " + statusCode);
        } else {
            Debug.WriteLine(ex.InnerException);
        }
        return true;
    });
};

apnsBroker.OnNotificationSucceeded += (notification) => {
    Debug.WriteLine("Apple Notification Sent!");
};

apnsBroker.Start();

foreach (var deviceToken in to)
{
    apnsBroker.QueueNotification(new ApnsNotification
    {
        DeviceToken = deviceToken,
        Payload = JObject.Parse("{\"aps\":" + aps.ToString().Replace('=', ':') + "}")
    });
}

apnsBroker.Stop();

2 个答案:

答案 0 :(得分:1)

此错误是因为您使用的证书未启用推送。

您必须从apple id启用它,然后创建新证书(.12)和配置文件。

尝试使用新证书将解决您的错误。

答案 1 :(得分:0)

尝试将前两个参数仅传递给apnsconfiguration构造函数,或者删除validateIsApnsCertificate(bool)参数。 它对我的前三个参数都很好。

var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, P12Password);