2012-02-07 23 views
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; 
}); 

如何做到這一點?一些示例代碼將會很有幫助。

感謝 普什帕

+0

看到這個http://stackoverflow.com/q/4656214/845115 – 2012-02-07 05:45:41

回答

4

只能支持你的背景位置services.audio播放和VOIP服務.. 如果您的應用程序不請不要浪費使用這些API的和他們functions..than你的時間做這件事...即使有一些方法可以實現這一點,Apple也不會接受你的應用程序。

相關問題