Question

I am using beginBackgroundTaskWithExpirationHandler at many places in my app whenever it's necessary to complete a task and I do endBackgroundTask when the task is over. There are some crucial parts of my code where i want to know whether the app currently can suspend (if backgrounded).

So, whenver I do endBackgroundTask, I want to check whether any UIBackgroundTaskIdentifier in the entire app is not UIBackgroundTaskInvalid so that I can notify all the the crucial parts that the app is no longer protected by any beginBackgroundTaskWithExpirationHandler and is supendable. Is there any property of [UIApplication sharedApplication] which will store these values? Or any other way to know that?

Was it helpful?

Solution

I believe you have to store the value of this as a property if you want to access it from lower down in your app. If you store it as a property of your app delegate you can access it anywhere by:

[[[UIApplication sharedApplication] delegate] backgroundTask]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top