Background fetch is not working after killing the app

Meryem Uysal picture Meryem Uysal · Feb 18, 2016 · Viewed 11.8k times · Source

I'm trying to get data from url with background fetch. My func tries to get data and if there is a new data, it sends local notification. Background fetch works after about 10 - 20 minutes when i minimize the app. But when i kill the app (double click home button and close app) it doesn't work. I waited about 1 hour but it didn't work. I am using background service in android and it is working successfully. Is there any way to get data from url and send local notification when app is closed? I am using Xcode 6 and swift 1.2

Answer

Alex picture Alex · Feb 18, 2016

The Background Fetching will NOT happen in your app after the user has killed it in the multitasking UI. This is by design.

Take a look at Apple's documentation that mentions:

Apps that support background execution may be relaunched by the system to handle incoming events. If an app is terminated for any reason other than the user force quitting it, the system launches the app...

and

In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system.

As you noticed in the documentation, there's only 1 exception when the app will be relaunched if it was force killed: by using location services. Unfortunately this does not apply to you.

Also, you cannot detect if the app was force killed by the user. Check this StackOverflow answer.