バックグラウンドで実行中に数分後にアプリケーションを終了したいと考えています。私はバックグラウンドで実行中に数分後にアプリケーションを終了したい
手順は次のとおりです。
アプリをバックグラウンドで実行します。 2分後、アプリは自動的に終了します。
私は以下のような方法を見つける:あなたが見るように、私はその場所にタイマーを追加したい 、
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
//============================
// here i want to add a timer
//=============================
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
。
タイマーはバックグラウンドでは機能しませんでした。私もperformSelectorを試しました:afterdelay:
どうすればいいですか?
申し訳ありません。あなたの立場は間違っています...実際、バックグラウンドでは何も働いていません。私はちょうどバックグラウンドでいくつかの仕事をすることができるタスクが欲しいです。しかし、アプリが戻ると、何も動くことはできません。 –