I am developing an iOS application and I'm using the
NSURLConnection sendAsynchronousRequest: queue: completionHandler:
method. When I started testing the app on the iPhone, whenever the app is calling the method and I lock the phone, the method returns an error. Why is this so? Is there anyway I can prevent it from doing this, so that the method still runs even when the phone is locked?

- 570
- 16
- 36

- 11
- 1
2 Answers
Your app is placed in the background when the UI is locked. The same thing will happen if someone presses the home button while your app is running. You should change your app to handle being placed in the background.

- 15,922
- 4
- 48
- 73
this may help --
applicationProtectedDataWillBecomeUnavailable
If your application is currently accessing a protected file, you can use this method to release any references to that file. Although it is not an error to access the file while the device is locked, any attempts to do so will fail. Therefore, if your application depends on the file, you might want to take steps to avoid using that file while the device is locked.
On a device that uses content protection, protected files are stored in an encrypted form and made available only at certain times, usually when the device is unlocked. This notification lets your application know that the device is about to be locked and that any protected files it is currently accessing might become unavailable shortly.

- 13
- 2