苹果推送通知与APNS锐利

时间:2010-07-01 22:14:16

标签: c# iphone push-notification apple-push-notifications apns-sharp

我使用APNS Sharp库进行苹果推送通知。我已经从Here下载。我使用APNS sharp库提供的样本测试程序,没有任何修改。 它只是在我在该行代码处放置断点之前不会发送任何通知。 如果我提出突破点。我只是工作正常。这是预期的行为,或者我做错了什么。而且我也没有任何例外。谢谢你的帮助。 这是代码

static void Main(string[] args)
{
    bool sandbox = true;
    string testDeviceToken = "Token";
    string p12File = "apn_developer_identity.p12";
    string p12FilePassword = "yourpassword";
    int sleepBetweenNotifications = 15000;
    string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
    NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);
    service.SendRetries = 5; 
    service.ReconnectDelay = 5000; //5 seconds
    service.Error += new NotificationService.OnError(service_Error);
    service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
    service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
    service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
    service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
    service.Connecting += new NotificationService.OnConnecting(service_Connecting);
    service.Connected += new NotificationService.OnConnected(service_Connected);
    service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
    Notification alertNotification = new Notification(testDeviceToken);
    alertNotification.Payload.Alert.Body = "Testing {0}...";
    alertNotification.Payload.Sound = "default";
    alertNotification.Payload.Badge = i;
    if (service.QueueNotification(alertNotification))
      Console.WriteLine("Notification Queued!");
    else
      Console.WriteLine("Notification Failed to be Queued!");
    Console.WriteLine("Cleaning Up...");

    service.Close();// if i dont put a break point in here, it simply does not send any notification

    service.Dispose();

}

我希望我的问题很清楚...... 更新:我被困在这里。任何人都可以帮助我。

2 个答案:

答案 0 :(得分:2)

我发现了问题。这是APNS SHARP库线程工作流程中的错误。

编辑:
排队所有通知后,我正在调用此方法 喜欢 service.start();
这是方法

     public void Send()
    {
        foreach (NotificationConnection conn in this.notificationConnections)
        {
           // Console.Write("Start Sending");
            conn.start(P12File, P12FilePassword);
        }
    }

答案 1 :(得分:1)

我也看到了这一点。看看NotificationConnection.Close()方法,我发现了这个:

//在这里睡觉以防止比赛情况 //在工作线程中可以将通知排队 //在循环后休眠,但如果我们在100毫秒内设置关闭为真, //在此期间排队的通知不会作为循环出列 //会因为closing = true而退出; // 250毫秒应该是循环使任何剩余通知出列的充足时间 //在我们停止接受上述之后 Thread.sleep代码(250);

在提到的循环中我发现: Thread.sleep代码(500);

将close方法中的睡眠时间设置为1000为我修复它;)   - 回答:http://code.google.com/p/apns-sharp/issues/detail?id = 41

相关问题