开发者

Running code in a timer while application is in the background

开发者 https://www.devze.com 2023-04-11 15:17 出处:网络
Is it possible for this situation to happen: My application enters the background, I want a NSTimer to run in the

Is it possible for this situation to happen:

My application enters the background, I want a NSTimer to run in the

- (void)applicationDidEnterBackground开发者_开发知识库:(UIApplication *)application

method, every two or so seconds. I know how to initiate the timer, however what I want to know is if I can run code every 2 seconds or whatever I choose in the background? Or is it once the application has entered the background code cannot be run. I know with android if applications are left open but minimised you can run code as they continue to run in the background.


You've doubted it correct. The application that enters background can not run. So, you can not execute your code while the app in background. I'd suggest you to go through the Apple's doc Executing Code in the Background. It begins with,

"Most applications that enter the background state are moved to the suspended state shortly thereafter. While in this state, the application does not execute any code and may be removed from memory at any time."

But the services audio, location and voip are allowed to run in background. For those services the background execution must be declared in advance by the application that uses them.


If you move your application to background and declare the application as audio it will run.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号