Is it safe to call `beginBackgroundTaskWithExpirationHandler` in `applicationWillEnterForeground`?

I wanted to understand if it is safe to call beginBackgroundTaskWithExpirationHandler in applicationWillEnterForeground or if it should only be called when the app is going to enter the background?

My requirement is that I have a thread running which sends data to the server, and I want to ensure that when the app enters the background, it sends some extra information (like the app has been backgrounded and some other events that occurred while the app was in the foreground). This may take some time to complete. So, I'm trying to understand the best practice for calling beginBackgroundTaskWithExpirationHandler.

Answered by Scott in 760897022

It’s safe. Note this line in the documentation:

You can call this method at any point in your app’s execution.

Accepted Answer

It’s safe. Note this line in the documentation:

You can call this method at any point in your app’s execution.

Is it safe to call `beginBackgroundTaskWithExpirationHandler` in `applicationWillEnterForeground`?
 
 
Q