iOS NSURLSessionDelegate [URLSession: task: didCompleteWithError:] returns with error if app is suspended

I'm writing an app that requires background downloading. I've configured my NSURLSession to be in the background Session Configuration.

Everything is working when the app is in foreground or even in background mode (home button), but as soon as I press the power button to force the phone into sleep mode. The NSURLSession delegate call:

- (void)URLSession:(NSURLSession *)session 
        task:(NSURLSessionTask *)task 
        didCompleteWithError:(NSError *)error

returns with a Error Domain=NSPOSIXErrorDomain Code=1 "The operation couldn’t be completed. Operation not permitted" and my download fails.

Answers


You have forgotten the bg-download entitlements (see target -> capabilities)


Need Your Help

String Comparison, .NET and non breaking space

c# string character-encoding

I have an app written in C# that does a lot of string comparison. The strings are pulled in from a variety of sources (including user input) and are then compared. However I'm running into problems...

How to globally config Laravel's Route::resource to be compatible with ng.resource (a Laravel route for each ng resource)?

angularjs laravel rest http laravel-5

Laravel 5 uses put/patch verbs to update a resource while Angular ng.resource uses post by default for both create and update. How to globally set Laravel's Route::resource to follow the Angular be...