Question

I am using a webservice to fetch data from the server. It is working fine when the device is unlocked. But while loading data, if I lock the iPhone, and unlock it, I receive empty data.

Someone provide me a solution to avoid this problem?

Was it helpful?

Solution

If you lock the phone, the app is backgrounded. When you wake it back up, the connection will have been cancelled and your data incomplete (depending on what you do) or no data at all.

I'd suggest you read up on background loading of data with the URL loading system and use that: https://developer.apple.com/library/iOS/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top