iPhone推送通知错误

时间:2011-06-14 08:23:30

标签: c#-4.0 apns-sharp

创建了一项服务,使用 APNS-SHARP 向iPhone发送推送通知。在关闭连接时,我收到错误消息 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应17.149.34.140:2195."下面是我的代码

    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);

                        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)
        {

        }
    }

1 个答案:

答案 0 :(得分:0)

解决了apns sharp lib中的错误

相关问题