Pushsharp 4.0.10 "Connection Error" for iOS device tokens

I developed a Windows service to send push notifications to iOS and Android applications using the pushsharp library. I recently upgraded the library from 2.xx to 4.0.10, and GCM notifications are sent normally, but Ios notifications are not sent, always getting a "Connection Error". I need to send notifications to thousands of tokens. Therefore, I look through all the tokens and queues. Even for 10 tokens, the same error also occurs. Please suggest me what is wrong with my code. Here is my code snippet

public static void SendNotifications(List currentBrandNotications, long brandId) { byte[] appleCert = null; string p12File = @"aps_production_brand" + brandId.ToString().Trim() + ".p12"; try { appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "P12\\" + p12File)); } catch (Exception ex) { logger.Debug("P12 certificate is not avilable for BrandId: " + brandId); } try { logger.Debug(" Send PushNotifications To Apple :- "); if (appleCert != null) { // Configuration var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, currentBrandNotications[0].P12Password); // Create a new broker var apnsBroker = new ApnsServiceBroker(config); var fbs = new FeedbackService(config); // Wire up events apnsBroker.OnNotificationFailed += (Notification, aggregateEx) => { //ScheduledNotification ScheduledNotification = new InstantPNScheduler.ScheduledNotification(); aggregateEx.Handle(ex => { // See what kind of exception it was to further diagnose if (ex is ApnsNotificationException) { var notificationException = (ApnsNotificationException)ex; // Deal with the failed notification var apnsNotification = notificationException.Notification; var statusCode = notificationException.ErrorStatusCode; logger.Debug("Apple Notification Failed: ID=" + apnsNotification.Identifier + " Code=" + statusCode); } else { // Inner exception might hold more useful information like an ApnsConnectionException logger.Debug(ex.InnerException.ToString()); } // Mark it as handled return true; }); }; apnsBroker.OnNotificationSucceeded += (Notification) => { logger.Debug("Apple Notification Sent!"); }; // Start the broker apnsBroker.Start(); foreach (ScheduledNotification notification in currentBrandNotications) { try { //logger.Debug("iOS Device token=" + notification.DeviceToken); apnsBroker.QueueNotification(new ApnsNotification { DeviceToken = notification.DeviceToken, Payload = JObject.Parse("{\"aps\":{\"alert\":\"" + notification.Message + "\",\"badge\":1,\"sound\":\"sound.caf\",\"BrandId\":\"" + brandId.ToString() + "\",\"notificationType\":\"Basic\",\"DeviceType\":\"" + notification.DeviceType + "\",\"DeviceToken\":\"" + notification.DeviceToken + "\",\"NotificationId\":\"" + notification.NotificationId + "\"}}") }); } Thread.Sleep(800); } catch (Exception ex) { logger.Debug(" SendPushNotificationToApple :- " + ex.Message); } } // Stop the broker, wait for it to finish // This isn't done after every message, but after you're // done with the broker apnsBroker.Stop(); } } catch (Exception ex) { logger.Debug("Error" + ex.Message); } finally { //apnsBroker = null; } } 

Note. If I put the thread.sleep (800) loop in the for loop, then notifications will be sent, but it's too late in the case of thousands of tokens. I need this without thread.sleep (800), even if I reduce below 800 ms, getting the same exception. Please help me what is wrong with my code. Any help would be appreciated.

+5
source share

All Articles