Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I avoid UI when iOS app is launched in background

My app supports background location updates (specifically with significant location monitoring).

Do I need to prevent UI (via controllers etc.) from loading when I identify that the app is in background (application.applicationState == UIApplicationStateBackground)?

My intention is to avoid heavy UI loading (it's a BIG app) in background, that might waste all the limited time I have in background to actually respond to the location update.

For example (in ObjC, but the question is also for Swift), let's say I have some RootViewController which initializes and holds the whole controllers/view hierarchy, should I, in the viewDidLoad do:

if ([UIApplication sharedApplication].applicationState ==  UIApplicationStateBackground) {
    // Root view controller loaded while in background, so doing only background stuff
    [self justDoBackgroundStuffWithoutUI];
} else {
    // Root view controller loaded normally, so loading normal UI
    [self initializeUIAndChildControllers];
}

? Or should I just "trust" iOS to ignore all of those UI tasks, because it will know it's in a background state?

like image 970
mllm Avatar asked Jan 05 '17 10:01

mllm


1 Answers

You can ignore those and let the OS handle that, just be careful if you have long running BG tasks, they may or may not have time to complete so it is best to very careful as it won't allow you to run tasks forever.

like image 52
Matt Douhan Avatar answered Sep 28 '22 09:09

Matt Douhan