Backgound Fetch doesn't work properly

Hi!

I want to build an app which fetches a small amount of information from the web and gives a notification once a day. I would say this is a typical use for a background fetch.


I have everything implemented but no matter which parameter i give to

setMinimumBackgroundFetchInterval

(lets say 600 for 10 Minutes, 1800 for half an hour, the constant UIApplicationBackgroundFetchIntervalMinimum)

the backgound fetch doesn't work properly.


Sometimes it gives me 2-3 times in an hour a fetch, sometimes for more than 24 hours NOTHING happens.

What am I doing wrong? Does someone have a WORKING Swift example who can share it with me?

THANK YOU VERY MUCH.

Don't forget to set the plist. You need add UIBackgroundModes key with the fetch value in your app’s Info.plist file


I found several examples :

https : / / www.raywenderlich.com/143128/background-modes-tutorial-getting-started


or (objC, but should be easy to port to Swift)

http : / / hayageek.com/ios-background-fetch/

or this one

http : / / corsarus.com/2015/background-fetching-using-nsurlsession/

I had a similar issue and the problem is in the wording.


setMinimumBackgroundFetchInterval sets just that, the MINIMUM amount of time that your app will wait before attempting a background fetch. Not the maximum amount of time, but the "don't check more often than this" amount of time.


So even if you set the interval to 5 minutes, it could still be 24 hours before a fetch is attempted. You could also get 4 background fetches in an hour, but they'll be at least 5 minutes apart.


If you set the interval to 60 minutes, then you're guaranteed that it won't attempt another background fetch for AT LEAST an hour.


Instead of using a background fetch combined with a local notification, you might need to attempt a full blown push notification (which when your app receives it, downloads the data it needs, prior to notifying the user). It's significantly more work, but you'll have much better control over how often it does or does not occur.


Hope this helps,

Glen

Could you tell me how do you fix this issue ?

Backgound Fetch doesn't work properly
 
 
Q