开发者

iPhone push notification error

t have created a service for sending push notification to iPhone by using APNS-SHARP .while closing the connection i am getting an error that " A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 17.149.34.140:2195." below is my code

    public void SendPushNotificationToiPhone()
    {
        try
        {
            int iPhoneCount = 1;
            NotificationService pushNotificationService = null;
            using (WhatsNewAtDbEntities entityObject = new WhatsNewAtDbEntities())
            {
                var activeiPhoneDevices = from items in entityObject.PushNotifications
                                          where items.IsActive == 1 &&
                                          items.Make == 2
                                          select items;

                int activeiPhoneDevicesCount = activeiPhoneDevices.Count();

                foreach (var activeDevicesDetails in activeiPhoneDevices)
                {
                    string deviceToken = activeDevicesDetails.NotificationUrl;
                    int counter = 0;

                    using (WhatsNewAtDbEntities objnewent = new WhatsNewAtDbEntities())
                    {
                        List<ContentCount_Result> count = objnewent.ContentCount(activeDevicesDetails.UserID, activeDevicesDetails.TenantID).ToList<ContentCount_Result>();
                        counter = Convert.ToInt32(count[0].Notificationcount);
                    }

                    if (iPhoneCount == 1)
                    {
                        //True if you are using sandbox certificate, or false if using production
                        bool sandbox = Convert.ToBoolean(AzureData.GetConfigurationSetting("sandBoxCert"));
                        string p12File = AzureData.GetConfigurationSetting("certName");
                        string p12FilePassword = AzureData.GetConfigurationSetting("certPassword");

                        string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
                        pushNotificationService = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);

   开发者_StackOverflow社区                     pushNotificationService.SendRetries = 5; //5 retries before generating notificationfailed event
                        pushNotificationService.ReconnectDelay = 5000; //5 seconds 

                    }
                    Notification alertNotification = new Notification(deviceToken);
                    if (counter > 0)
                    {
                        alertNotification.Payload.Badge = counter;
                    }
                    else if (counter == 0)
                    {
                        //for resseting the badge value to 0(zero).
                        alertNotification.Payload.Badge.GetValueOrDefault(0);
                    }

                    //Queue the notification to be sent
                    pushNotificationService.QueueNotification(alertNotification);

                    if (iPhoneCount == activeiPhoneDevicesCount)
                    {
                        //First, close the service.
                        pushNotificationService.Close(); --**Getting error here**
                        ////Clean up
                        pushNotificationService.Dispose();
                    }

                    iPhoneCount++;
                }
            }
        }
        catch (Exception)
        {

        }
    }


Got solved there was an bug in the apns sharp lib

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜