Search code examples
swiftnsoperationqueuensoperation

Should OperationQueue execution be canceled when application is suspended?


I am interested if it is required to call .cancelAllOperations() in the OperationQueue when application receive UIApplicationWillResignActive notification?


Solution

  • The application will likely enter the suspended state after entering background:

    The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended.

    The Apple documentation tells us that the background state is a transitory state, and from this state it can go only to suspended, meaning that no code from your app will be executed.

    This means that any operations that you enqueued are also "paused". You can cancel them if the operations don't react very well when being "resumed" after a while, otherwise you can leave them untouched.