Share extension: Background NSURLSessionUploadTask cannot read file in app group shared container (on device)

Originator:bryan
Number:rdar://18107172 Date Originated:8/22/2014
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 8b5
Classification:Serious bug Reproducible:Yes
 
Summary:
I am building a share extension that uses an NSURLSession with a background configuration to create an NSURLSessionUploadTask. The extension writes a file into the app group's shared container, which the session task is supposed to upload. 

This works in the simulator but the NSURLSessionUploadTask fails to read the file from the app group's shared container when the extension is run on a device (iPhone 5S).

Steps to Reproduce:
* Write a file to disk (in the app group's shared container), intended to serve as an HTTP request body
* Create an NSURLSession with a background configuration
* Create an NSURLSessionUploadTask with the file path of the aforementioned request body file

Expected Results:
The NSURLSessionUploadTask should be able to read the file out of the app group's shared container and POST it to the server

Actual Results:
The NSURLSessionUploadTask fails to read the file when the extension is being run on a device. It works when being run in a simulator. Here are the device logs (also included in the attached .zip file):

Aug 22 17:37:34 BryPhone-5 ShareExtension[1484] <Error>: Failed to issue sandbox extension for file file:///private/var/mobile/Containers/Shared/AppGroup/DAC0CE53-E97B-40D8-B636-18F85460DC2B/requestBody.txt, errno = 1
Aug 22 17:37:34 BryPhone-5 nsurlsessiond[101] <Error>: Error linking upload file: Error Domain=NSCocoaErrorDomain Code=257 "The operation couldn’t be completed. (Cocoa error 257.)" UserInfo=0x145bc9f0 {NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/DAC0CE53-E97B-40D8-B636-18F85460DC2B/requestBody.txt, NSUnderlyingError=0x145c38e0 "The operation couldn’t be completed. Operation not permitted"}
Aug 22 17:37:34 BryPhone-5 MobileSafari[1479] <Critical>: Errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo=0x18225170 {NSLocalizedDescription=query cancelled}
Aug 22 17:37:34 BryPhone-5 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system) <Error>: Caller not allowed to perform action: MobileSafari.1479, action = sandboxed lookup, code = 1: Operation not permitted, uid = 501, euid = 501, gid = 501, egid = 501, asid = 0
Aug 22 17:37:34 BryPhone-5 MobileSafari[1479] <Warning>: LaunchServices: invalidationHandler called
Aug 22 17:37:34 BryPhone-5 MobileSafari[1479] <Notice>: 2014-08-22 17:37:34.398|MobileSafari|0x16e21420: SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "The operation couldn’t be completed. (_UIViewServiceErrorDomain error 1.)" UserInfo=0x16dc7740 {Terminated=disconnect method}

Version:
iOS 8b5

Notes:


Configuration:
iPhone 5 64GB Verizon

Attachments:
'extension-sample-project.zip' was successfully uploaded.

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!