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