C# 4.0 iPhone推送通知错误

C# 4.0 iPhone推送通知错误,c#-4.0,apns-sharp,C# 4.0,Apns Sharp,我没有使用APNS-SHARP创建向iPhone发送推送通知的服务。在关闭连接时,我收到一个错误 “连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机没有响应17.149.34.140:2195。”下面是我的代码 public void SendPushNotificationToiPhone() { try { int iPhoneCount = 1; Notifi

我没有使用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)
        {

        }
    }
public void sendpushNotificationtoPhone()
{
尝试
{
intiphonecount=1;
NotificationService pushNotificationService=null;
使用(WhatsNewAtDbEntities entityObject=new WhatsNewAtDbEntities())
{
var activeiPhoneDevices=来自entityObject.PushNotifications中的项
其中items.IsActive==1&&
items.Make==2
选择项目;
int-activeiPhoneDevicesCount=activeiPhoneDevices.Count();
foreach(activeiPhoneDevices中的var activeDevicesDetails)
{
string deviceToken=activeDevicesDetails.NotificationUrl;
int计数器=0;
使用(WhatsNewAtDbEntities objnewent=newwhatsnewatdbentities())
{
List count=objnewent.ContentCount(activeDevicesDetails.UserID,activeDevicesDetails.TenantID).ToList();
计数器=Convert.ToInt32(计数[0].Notificationcount);
}
如果(iPhoneCount==1)
{
//如果您使用的是沙盒证书,则为True;如果使用的是生产证书,则为false
bool sandbox=Convert.ToBoolean(AzureData.GetConfigurationSetting(“sandBoxCert”);
字符串p12File=AzureData.GetConfigurationSetting(“certName”);
字符串p12FilePassword=AzureData.GetConfigurationSetting(“certPassword”);
字符串p12Filename=System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,p12File);
pushNotificationService=新的NotificationService(沙盒,p12文件名,p12文件密码,1);
pushNotificationService.SendRetries=5;//在生成notificationfailed事件之前重试5次
pushNotificationService.ReconnectDelay=5000;//5秒
}
通知alertNotification=新通知(deviceToken);
如果(计数器>0)
{
alertNotification.Payload.Badge=计数器;
}
else if(计数器==0)
{
//用于将徽章值重新设置为0(零)。
alertNotification.Payload.Badge.GetValuerDefault(0);
}
//将要发送的通知排队
pushNotificationService.QueueNotification(alertNotification);
如果(iPhoneCount==activeiPhoneDevicesCount)
{
//首先,关闭服务。
pushNotificationService.Close();--**此处获取错误**
////清理
pushNotificationService.Dispose();
}
iPhoneCount++;
}
}
}
捕获(例外)
{
}
}

已解决apns sharp库中有一个错误

请详细说明错误,因为我也遇到了同样的问题