5

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();
Masoud Abedi
  • 51
  • 1
  • 5

2 Answers2

1

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.

Neelam Prajapati
  • 3,586
  • 2
  • 21
  • 60
0

Try by passing only first two parameters to apnsconfiguration constructor, or else remove validateIsApnsCertificate (bool ) parameter. It's working fine for me first three parameters.

var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, P12Password);
sailaja m
  • 129
  • 1
  • 5