Ensure that critical tasks finish when your app moves to the background.
Extending your app’s background execution time ensures that you have adequate time to perform critical tasks. When your app moves to the background, the system calls your app delegate’s
application method. That method has five seconds to perform any tasks and return. Shortly after that method returns, the system puts your app into the suspended state. For most apps, five seconds is enough to perform any crucial tasks, but if you need more time, you can ask UIKit to extend your app’s runtime.
You extend your app’s runtime by calling the
begin method. Calling this method gives you extra time to perform important tasks. (Find out how much time remains using the
background property.) When you finish your tasks, call the
end method right away to let the system know that you are done. If you do not end your tasks in a timely manner, the system terminates your app.
Listing 1 shows an example that configures a background task so that the app may save data to its server, which could take longer than five seconds. The
begin method returns an identifier that you must save and pass to the