I'm attempting to upload large files as reliably as possible. I've chosen NSURLSession
using a NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier
configuration and then create and resume an upload task. Everything works great except if the user locks the screen while the file is being uploaded.
Originally, the upload would stop in 10 secs with a NSPOSIXErrorDomain
error code 1: "Operation not permitted". However after researching the issue here, I set the file's NSFileProtectionKey
to NSFileProtectionCompleteUnlessOpen
.
After that fix, the entire file is uploaded. I've confirmed that by looking at the file on the server. However I still get the same error upon completion.
I've confirmed that this does not occur if the device does not have a passcode set, so I think it still has something to do with file encryption/data protection. I've also tried setting the file's NSFileProtectionKey
to NSFileProtectionNone
, but still get the same error once the upload finishes.
I have no idea what the system is attempting to do that triggers this error. Is there an application file the system needs to write to once the upload completes? Does anyone have an idea what might be triggering an "Operation not permitted" error once a background upload completes, but before any of my application code is executed in the didCompleteWithError
?