Thank you. I've read this post in the past and it was quite enlightening. But, still, it does not answer the main quiestion.
"The workaround is to put the code that handles request completion in both your app and your extension (possibly reusing the code via a framework)."
How extension is supposed to notify the user if transfer fails and is non-retryable? What's Apple's vision of this? How do they do it in their own apps?
Basically, I want to design the app the way it would not be rejected from App Store. 🙂 From what I see so far (Google Drive, for example), this moment is completely overlooked by Apple and they "let slide" various workarounds. Which are:
- Calling containing app via traversing responder chain
- Insta-killing extension with exit(0)
- Doing transfers in foreground
In case there's no official solution, I wonder what is the safest workaround.
Update: As you correctly mentioned in your article, there's no way to give up NSURLSession voluntarily and it leads to a plethora of problems:
- We can't resume tasks in application:handleEventsForBackgroundURLSession:completionHandler: because obtaining session would lead to app owning the it until all tasks complete, effectively blocking extension process from adding tasks to it (though, this can be worked around by re-creating all pending tasks in application-private NSURLSession and calling invalidateAndCancel)
- We can't peek into shared session to show progress of a lengthy transfer (to show it in-app or, say, in today extension) - for the same reason
- We can't access shared session at any time to cancel its tasks (when user signs out from the app, for example) - because it can still be owned by extension process