Network lost when locking screen lock

A very strange problem was detected, using a simple download operation AFNetworking, even trying with a simple operation NSURLConnection, the connection will fail if you support the application and lock the screen and then unlock. Works great in backgroundthough.

Anyone faced with a similar problem with NSURLConnectionwant to share some solution?

Thank.

+4
source share
2 answers

This seems like an iOS bug. Strange, but the action of the screen NSURLSessionsomehow affects NSURLSession, so that it stops working and returns NSURLErrorNetworkConnectionLost. So in my application, I refused to use a shared session. I use a new session object for each request, or (if I need to constantly maintain one session), I recreate it every time the screen unlocks. And it works. AFNetworkingfor users AFNetworkingor any other third-party library working on top of the NSURLSessionsituation is more complicated. You will need to fix the library code, which is certainly not a good thing, but I think there is no other choice

+1
source

, , . NSURLSessionDataTasks , , .

:

  • NSMutableArray * dataTasksToResume

  • - (void) applicationWillResignActive: ( UIApplication *) dataTasksToResume

  • NSURLSessionDataTasks
  • - (void) applicationDidBecomeActive: (UIApplication *) ( )
  • !

, .

0

All Articles