Background NSURLSession not invalidated on iOS 10 after sending the app to background and back
| Originator: | gleb.arkhipov | ||
| Number: | rdar://28422096 | Date Originated: | 22.09.2016 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 10.0, 10.0.1 |
| Classification: | Other Bug | Reproducible: | Always |
Summary: Normally, when you call -finishTasksAndInvalidate on an NSURLSession, it calls -URLSession:didBecomeInvalidWithError on its delegate as soon as its last task is finished. However, that does not happen with a background session on iOS 10 if the app is sent to background state and back to foreground during download. Steps to Reproduce: Open the attached project and Product->Test it on iOS 10 Simulator or device. There is one UI test performing the steps listed below. Alternatively, you can Run the app and do the same steps manually: 1. Launch the app from the attached project on iOS 10 Simulator or device. 2. Tap "Start Download". 3. Wait for the download to finish. — The label below will say "Session invalidated", which is expected. 5. Tap "Start Download" again. 6. When the progress indicator starts moving again, press the Home button. 7. Wait 1-2 seconds and tap the app icon again to return to foreground. 8. Wait for the download to finish. — The label will say "Task completed" but never switch to "Session invalidated". Expected Results: -urlSession:didBecomeInvalidWithError: is called and the label shows "Session invalidated". Actual Results: -urlSession:didBecomeInvalidWithError: is NOT called and the label shows "Task completed", indicating that only -urlSession:didCompleteWithError: was called. Version: iOS 10.0 (14A345), iOS 10.0.1 (14A403) Notes: If you call -finishTasksAndInvalidate again after returning to foreground, the session _will_ call -urlSession:didBecomeInvalidWithError: on the delegate after finishing the tasks. Configuration: Tried on several iOS devices and simulators, probably any of those Attachments: 'URLSessionInvalidation.zip' was successfully uploaded. // also available here: https://github.com/glebon/URLSessionInvalidation
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!