2

アプリケーションがバックグラウンドになっても継続するはずのファイルをアップロードしたい。

現在、DBからファイルを取得し、NSOperationを介してキューに追加してから、アップロード手順を開始しています。

アプリがバックグラウンドまたはフォアグラウンドになった場合でも、すべてのファイルをアップロードする必要があります。以下は、単一のタスクのコードです。多くのファイルをアップロードするためにどのように機能させることができるかについて、誰かが私にヒントを与えることができます。

UIApplication* application = [UIApplication sharedApplication];
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
  // Clean up any unfinished task business by marking where you
  // stopped or ending the task outright.

  [application endBackgroundTask: bgTask];
  bgTask = UIBackgroundTaskInvalid;
}];
4

2 に答える 2

0

Appleは、アプリが必要な条件を満たす場合、バックグラウンドでの実行を許可します。 ここを参照してください

于 2012-07-10T09:17:16.390 に答える
0

これをやってみませんか?..まだ試していませんが、試した後にアップデートを投稿します

UIApplication* application = [UIApplication sharedApplication];
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
  // Clean up any unfinished task business by marking where you
  // stopped or ending the task outright.

  // Bring up your NSOperation queue instance here and block this thread until it is complete
  [queue waitUntilAllOperationsAreFinished];

  [application endBackgroundTask: bgTask];
  bgTask = UIBackgroundTaskInvalid;
}]; 

また、バックグラウンドでこれらの長年の操作をすべてキャンセルする方法があることを確認してください

 bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        // Clean up any unfinished task business by marking where you.
        // stopped or ending the task outright.
        [queue cancelAllOperations];

        [application endBackgroundTask:endSessionTask];
        bgTask = UIBackgroundTaskInvalid;
    }];
于 2012-11-05T23:49:10.957 に答える