0

私のアプリケーションでは、データの配列を処理し、インターネット接続が利用可能な場合にのみサーバーに送信する必要があります。アプリケーションの通常の実行が中断されないように、このタスクを別のスレッドで実行する必要があります。

ProcessQueue配列を反復処理してサーバーに送信するというクラスを作成しました。

ApplicationDidBecomeActive イベントでこのタスクを数秒の遅延で実行する必要がありますが、別のスレッドで実行する必要があります。

以下を試しましたが、セレクターが呼び出されません。(クラス内にブレークポイントを設定しようとしていますProcessQueue)。

dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    [self performSelector:@selector(processTheQueue) withObject:nil afterDelay:5];
    dispatch_async( dispatch_get_main_queue(), ^{

    });
});


- (void) processTheQueue
{

    QueueProcessor *process = [[QueueProcessor alloc] init];
    [process processQueue];

}

また、dispatch_async` 内で performSelector を使用しようとしまし[process processQueue]' method instead ofたが、機能しません。

4

1 に答える 1

1

これを試して..

   double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // code to be executed on main thread.If you want to run in another thread, create other queue
        [self repeateThreadForSpecificInterval];
    });
于 2013-06-18T13:13:14.287 に答える