Search code examples
ioscocoa-touchbackground-process

Is there a limit for background tasks?


What happens if I call beginBackgroundTaskWithExpirationHandler periodically every few minutes and never call endBackgroundTask?

Is there any limit for creating background tasks?


Solution

  • What happens if i call beginBackgroundTaskWithExpirationHandler periodically every minutes and never call endBackgroundTask

    • Nothing happens. Despite its name, beginBackgroundTaskWithExpirationHandler: does not actually "begin" a task. It might be better thought of as "register..." rather than "begin...." You're just telling the system that you're in the middle of doing something that would like to complete if that's ok.

    is there any limit for creating background task?

    • No. However, apps running background tasks have a finite amount of time in which to run them. (You can find out how much time is available using the backgroundTimeRemaining property.) If you do not call endBackgroundTask: for each task before time expires, the system kills the app. If you provide a block object in the handler parameter, the system calls your handler before time expires to give you a chance to end the task.

    This and this are good reads on the topic.