【问题标题】:iPhone push notification erroriPhone 推送通知错误
【发布时间】:2012-01-21 13:40:22
【问题描述】:

t 已经创建了一个使用 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)
        {

        }
    }

【问题讨论】:

    标签: c#-4.0 apns-sharp


    【解决方案1】:

    解决了 apns 锐利库中的一个错误

    【讨论】:

    • 您能否详细说明错误,因为我遇到了同样的问题
    猜你喜欢
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多