Should I avoid the user interface when the iOS application launches in the background

My application supports background location updates (especially with significant location monitoring).

Do I need to prevent the user interface from loading (via controllers, etc.) when I determine that the application is in the background ( application.applicationState == UIApplicationStateBackground )?

My intention is to avoid heavy loading of the user interface (this is a BIG application) in the background, which could result in the loss of all the limited time that I have in the background to actually respond to location updates.

For example (in ObjC, but the question is also for Swift), let's say I have some RootViewController that initializes and holds the entire hierarchy of controllers / views if I'm in 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 these UI tasks because it will know this in the background?

+6
source share
2 answers

You can ignore them and let the OS handle this, just be careful if you have long-running BG tasks, they may or may not have time to complete, so it’s best to be very careful, as this will not allow you to run tasks forever .

+4
source

Updating the user interface in the background is unnecessary, confusing, and inefficient.

  • unnecessary, since no value has been added to the user that the application is not using. Just doing things in viewWillAppear will suffice.
  • confusing, because users may expect to see the changes themselves, as the screen appeared, I don’t know your application, but this is more of a business choice. Perhaps you have something similar in the form of displaying changes, such as gmail / whatsapp, and you want users to see new messages.
  • inefficient because you just do something too long battery consumption. You even said "heavy loading of the user interface". What happens if the location changes over and over and over again? can changes be redefined in the sense that they are no longer needed or you will always need changes independently.

To summarize: I am not saying that I am not making any user interface updates, each application has a nice place. You probably won't need to do most of them and lazy upload changes, i.e. When loading the screen, it seems to be the best way. Although I am sure that there are some advanced recommendations that I do not know about. Hope other answers come.

+1
source

Source: https://habr.com/ru/post/1013783/


All Articles