Apns通知错误:'ConnectionError'且无法连接,请检查防火墙设置

时间:2017-06-27 05:03:49

标签: ios push-notification apple-push-notifications

我正在使用PushSharp 4.0.10并使用.p12证书我收到此错误 "Apns notification error: 'ConnectionError'" 而InnerException是 “无法连接,检查您的防火墙设置“ 。有人知道如何解决这个错误。

protected void Page_Load(object sender,EventArgs e){

    var certificate = System.IO.File.ReadAllBytes(System.Web.Hosting.HostingEnvironment.MapPath("~/jetzydev.p12"));
    var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, certificate, "12345");

    var apnsBroker = new ApnsServiceBroker(config);
    var fbs = new FeedbackService(config);

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

            return true;
        });
    };

    apnsBroker.OnNotificationSucceeded += (Notification) =>
    {
        Response.Write("done");
        //  logger.Debug("Apple Notification Sent!");                  
    };

    // Start the broker
    apnsBroker.Start();


    try
    {
        apnsBroker.QueueNotification(new ApnsNotification()
        {
            DeviceToken="---------------------------------------",
            Payload = JObject.Parse("{\"aps\":{\"alert\":{\"body\": \"This is message from local host 1\",\"title\": \"title\"},\"sound\":\"beep.wav\"}}")
        });
        apnsBroker.Stop();

    }
    catch (Exception ex)
    {
        Response.Write(ex);
        //logger.Debug(" SendPushNotificationToApple :- " + ex.Message);
    }

}

0 个答案:

没有答案