Background fetch in iOS 11.x


#1

Any issues using background fetch feature in iOS 11.x? (works perfectly in iOS 10.x _<)

// this method never gets called… (OS 11.1.2)
public func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {}

I understand that we have no power over when a background fetch will be performed exactly and we just have to set setMinimumBackgroundFetchInterval for the OS “Fetch content opportunistically in the background…”

Would like to ask alternatives to background fetch, if there’s any ^ (that would pass appstore review). Have to make this app work even in the background (works well is iOS 10<)


#2

You can use silent push notifications to initiate background fetch. Although, that would need to be started from a push server.


#3

Hi Mark, thank you for the suggestion, but unfortunately, the app just only use local notification. In iOS10, it works perfectly on the background or even in sleep mode, fetching/downloading logs approx around 10-25 mins if running solo. But in early versions of iOS11, it doesn’t trigger background fetch on sleep mode, while app is in the background.

Would like to ask if I could use an alarm manager or calendar component, to “schedule” and trigger the background fetch. (still local notification…).(is it acceptable>?) Today, will check iOS 11.4.1, and monitor if there are changes


#4

Yeah, I just recently saw that background fetch is bugged in early iOS 11 thanks to your post. Regression happens way too often in new major releases of iOS to be honest.

AFAIK, local notifications can’t really trigger background execution time. They only set a notification message that opens the app. Only when the app is opened can you execute any fetch. If that’s fine for you, you can set the local notification message to prompt the user to open the app. I get that kind of notif on freedom.to iOS app, whenever, I assume, their silent push notifications don’t work.

ex. “Your device put Freedom to sleep. Tap here to resume session activity.”

Is the background fetch failing in iOS 11.0x blocking your release? Background fetch in most cases should only be a nice to have feature since it’s not guaranteed to happen (only on the OS’ discretion). Not familiar with the use case you currently have but your app should still work fine when opened without a previous background fetch right?


#5

Hi Mark, we really appreciate your insights regarding the said issue, esp about local notifications and background fetch. It’s actually tough to reason out why a certain feature that works on a previous OS version, won’t work well now and defend that it isn’t a bug_^

Will keep on checking what could be the other work around. In case you have other more suggestions, do let us know^


#6

Is the app a VOIP app?


#7

Hi sir Naz, the app connects with bluetooth devices and part of its feature is to create local notifications (& download logs) in case there are new data to show to user. Works well in iOS10 but not in iOS11 _<


#8

Are the logs are updated and stored server side? If so,I think you should just use a push update (push notifications from server) vs a pull update process (background fetch). A lot more efficient too since you only push changes.

BUT iOS silent notifs are also bugged in early versions of iOS 11 too : https://stackoverflow.com/questions/44796613/silent-pushes-not-delivered-to-the-app-on-ios-11


#9

the logs are actually stored by the bluetooth device and we download it to update the app and notify the user thru local notification. We might consider push/silent to trigger app for the next ver and download the logs from the device. Just left a test device tonight and monitor if background fetch will be triggered. Haha, hoping mag trigger na sya :sob:


#10

Just an update, the background fetch is triggered on the test device every -/+ 3hrs. As also mentioned on StackOverflow, a number of factors are considered by OS before allowing background fetch. The factors present now is the app connected with the debugger and constant power source. Now testing if would replicate same behaviour if disconnected . Testing with iOS 11.1.2 and 11.4.1


#11

Ahh ok you were testing it while the device is connected to the debugger. Hey if it’s working that’s good news!

You can also use logging libraries like cocoalumberjack (https://github.com/CocoaLumberjack/CocoaLumberjack) if you want to inspect if background fetch triggers during normal use. You can just check the logs after a day or two. It’s what I used when checking background upload/download tasks when not connected to the debugger and the app is closed.


#12

thanks Mark, and this will definitely help us check things. About our test, unfortunately didn’t trigger today but will keep our test._^ haha, aja!