NSURLCredential when locked

I am building an app that is highly reliant on a web service API that requires HTTP Basic Authentication.


I use NSURLCredentials with Permanent persistance to store the user's username and password, and use that while making GET or POST Requests. This works very well if the app is in the foreground or in a background fetch, as long as the screen is not locked. If a background fetch occurs when the screen is locked, I get a 401 unauthorized error(which I see in the Xcode console). I believe this is due to NSURLCredential being unable to access Keychain stored items when the screen is locked. How can I set NSURLCredential to "Allow after first unlock" or "Allow Always", so that it can access keychain even when the the device is on the lockscreen?

NSURLCredential when locked
 
 
Q