1
我已經在ios5中實現了長時間運行的處理方法。我想在應用程序處於後臺時每隔30秒或1分鐘觸發一些功能。我已經編寫了代碼來執行長時間運行的進程,但在進入後臺方法時,我無法在進入後臺方法時執行定時器功能背景。我應該在哪裏放置我的定時器功能,以便它應該調用目標方法,即使它在後臺。如何運行我的應用程序在ios5中每隔30秒運行一次?
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you.
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(targetMethod) userInfo:nil repeats:YES];
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
如何做到這一點?一些示例代碼將會很有幫助。
感謝 普什帕
看到這個http://stackoverflow.com/q/4656214/845115 – 2012-02-07 05:45:41