3

Apple プッシュ通知に APNS Sharp ライブラリを使用しています。ここからダウンロードしました。APNS シャープ ライブラリが提供するサンプル テスト プログラムを変更せずに使用します。
そのコード行にブレークポイントを置くまで、通知を送信しません。ブレークポイントを入れると。私は正常に動作します.これは予想される動作ですか、それとも何か間違ったことをしています. また、例外はありません。助けてくれてありがとう。ここにコードがあります

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

}

私の質問が明確であることを願っています...
更新:私はここで立ち往生しています。誰かが私を助けてください。

4

2 に答える 2

2

私は問題を発見しました。APNS SHARP ライブラリ スレッド ワークフローのエラーでした。

編集:
すべての通知をキューに入れた後、このメソッドを呼び出しています。 service.start();
のように そしてここに方法があります


     public void Send()
    {
        foreach (NotificationConnection conn in this.notificationConnections)
        {
           // Console.Write("Start Sending");
            conn.start(P12File, P12FilePassword);
        }
    }
于 2010-07-11T02:21:50.557 に答える
1

私もこれを見ています。NotificationConnection.Close() メソッドを見ると、次のことがわかりました。

// ここでスリープして、// ワーカー スレッドがループ後にスリープしている間に通知がキューに入れられる可能性があるという競合状態を防ぎます。 // 閉じているためにループが終了するため、キューから取り出されません = true; // 250 ミリ秒は、Thread.Sleep(250) を超える受け入れを停止した後、// ループが残りの通知をデキューするのに十分な時間です。

そして、言及されたループで私が見つけた: Thread.Sleep(500);

close メソッドのスリープ時間を 1000 に設定すると修正されました;) - からの回答:http://code.google.com/p/apns-sharp/issues/detail?id=41

于 2011-04-05T15:40:30.100 に答える