iOS: Shared control over background NSURLSession (app + extension)

Consider the following situation: user uploads a large file via a share extension (extension writes upload details into shared DB and initiates background transfer), then quickly realizes that's a wrong file, so he switches to containing app, opens up a list of uploads and hits "Cancel".

Question is, how containing app is supposed to reliably cancel such transfer, given that only one process can access same NSURLSession at the time, a session is not disconnected until all tasks are complete (or connected process is terminated) and extension may not be terminated yet?

The share extension typically terminates immediately after the user is done sharing, which allows the app to connect up to the shared session. Admittedly, I haven’t played around with this in a long time, but the last time I did I wrote up my results as Networking in a Short-Lived Extension.

Be careful about testing this from within Xcode. It’s debugging may extend the process lifetime.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

iOS: Shared control over background NSURLSession (app + extension)
 
 
Q