The key to understanding is that instead of a completion handler, you have an expiration handler. It executes this line only as a "cleanup" of your code, making a long output.
To clear, he has a nuclear weapon / kill / complete the background task. Therefore, you must first stop it:
[application endBackgroundTask:bgTask]
Then it also sets a flag in the task so that it no longer runs.
bgTask = UIBackgroundTaskInvalid;
The reason you see this twice in the code is because:
- It successfully works in the background and ends in the sending block ... so you need to inform the application that I have finished.
- You do not finish in the background, but the application seems to be timed! You have to go ... cleanse yourself by making
[application endBackgroundTask:bgTask]; + bgTask = UIBackgroundTaskInvalid;
Honey source share