Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSUrlSession suspend and resume issue on device lock

Tags:

I am uploading file to server by using multipart form data with NSURLSession. When the application goes in background I want to suspend the request and resume when application comes in foreground again. So I simply do [session suspend] and [session resume]. This is working fine when the app goes in background only. But if the device gets locked, when going back in foreground and try to resume, I get a network connection lost error. I understand that when device is locked, all open sockets are closed and therefore the issue, but is there some way to make this work without the need of starting the upload from beginning?

like image 413
Ivan Alek Avatar asked Feb 17 '17 08:02

Ivan Alek


1 Answers

You should switch your foreground session to a background session before the app goes to background, and then there is no need to suspend it. Your file will be uploaded by OS while in background (eventually).

like image 97
Milan Markovic Avatar answered Sep 24 '22 10:09

Milan Markovic