ios - PushSharp Apns 通知错误 : 'ConnectionError'

标签 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();

最佳答案

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

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

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

关于ios - PushSharp Apns 通知错误 : 'ConnectionError' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38117258/

相关文章:

javascript - 从未在 ApiController 中调用 Post 方法

ios - Worklight 的临时推送通知和开发

ios - ionic 5 电容器 : Push Notification with ONESIGNAL not working on iOS

ios - 苹果推送通知一个应用多个子域

ios - 比较ios中的两个时间值?

ios - 如何在 iOS 中设置闹钟?

ios - 如何限制用户在 iOS 应用程序中使用后置摄像头

ios - 如何在 ios 6.0 中使用 CGContextDrawImage 获取椭圆的边框

javascript - knockout MVC,绑定(bind)模型并将对象添加到模型

c# - 在 MVC/Razor 中,如何获取多个复选框的值并将它们全部传递给 Controller ​​?