Perform background tasks when app is terminated

You have two options

  1. Background App Refresh
  2. Silent push notifications

Easiest one is Background App Refresh. Because later one needs a server to send the notification. You can check following API for the usage. Basically you set Background Fetch capability on Capabilities/Background Modes of your app. Then from time to time, iOS will wake up your app and call application(_:performFetchWithCompletionHandler:) delegate. You will have around 30-45 seconds to call your function and call completion handler. If you don’t finish it on time, iOS will kill your app. If you don’t obey the rules, iOS will give you less chances to wake up. For more detailed usage of Background Modes, you may check following tutorial

Leave a Comment