You can temporarily disable automatic locking until the request is completed and set [UIApplication sharedApplication].idleTimerDisabled to YES .
Another option is to set the web service request as the final task running in the background , so even if your device goes to sleep, the request continues to work. Beware of the 10 minute time limit.
In any case, when starting in the foreground, make sure the request is executed asynchronously and does not block the main thread, or your application will always be killed after that for too long.
source share