What's the difference between UIBackgroundTaskInvalid and endBackgroundTask?

549 views Asked by At

I sometimes see code where the task is ended using

bgTaskID = UIBackgroundTaskInvalid

At other places I see

UIApplication.sharedApplication().endBackgroundTask(bgTaskID)

At some other places I see:

  UIApplication.shared.endBackgroundTask(bgTaskID)
  backgroundTask = UIBackgroundTaskInvalid

What's the difference between these three? Reading from here it seems it's just a matter of clean code, but I find that unnecessary, you've ended the task!

To me they are all the same. Only that using you UIBackgroundTaskInvalid you can validate if a task has ended or not. Not sure why you'd ever need to validate though.

Is the above assessment correct?

0

There are 0 answers