Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PushSharp Apns notification error: 'ConnectionError'

I'm using PushSharp 4.0.10, MVC 4 with c#
In the OnNotificationFailed event of the Apns broker, I get ConnectionError exception.
This exception happened suddenly after change certificate(.p12) file; and it worked fine before this change.
Please advise how to troubleshoot this error.

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();
like image 636
Masoud Abedi Avatar asked Nov 08 '22 12:11

Masoud Abedi


1 Answers

this error is because certificate you used is not enabled pushnotification.

you have to to enable it from apple id and then create new certificate (.12) and provisioning profile.

try with that new certificate will resolve your error.

like image 168
Neelam Prajapati Avatar answered Nov 14 '22 21:11

Neelam Prajapati