是,接收暫時中斷時,從UIApplication的下列方法被調用 [Apple's documentation]:
- (void)applicationWillResignActive:(UIApplication *)application
它們與定時器和週期性任務指任務是這幾樣正在與週期執行計時器。例如,您可以在後臺運行一個計時器來更新視圖的內容。然後,當應用程序將退出活動狀態時,您應該停止該計時器。
例如,假設您正在運行的定時器來執行任務,每10秒:
// AppDelegate.m
// When application becomes active the timer is started
- (void)applicationDidBecomeActive:(UIApplication *)application {
self.timer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(scheduledTask:)
userInfo:nil
repeats:YES];
}
// When the application will resign active the timer is stopped
- (void)applicationWillResignActive:(UIApplication *)application {
[self.timer invalidate];
self.timer = nil;
}
計劃任務將是:
- (void)scheduledTask:(NSTimer *)timer {
// Up to you... for instance: web service call
}
與代碼片段的例子會更好地服務。無論如何感謝 – clint
示例添加到問題。如果有用,請投票:-) – atxe