AFNetworking default runLoopModes is NSRunLoopCommonModes.I want use NSDefaultRunLoopMode,and set it
operation.runLoopModes = [NSSet setWithObject:NSDefaultRunLoopMode];
But it doesn’t work. when I scroll the scrollView,download task still running.
Anybody can help me? thanks.
Recently I encountered similar question, while I was implementing images lazy loading in UITableView. User scrolling should have higher priority here.
Your direction is correct, the problem is in runloop modes. With UIImageView+AFNetworking extension, images are loaded with AFURLConnectionOperation, which is working on a separate network thread (see implementation), so NSURLConnections are running not on main thread.
To make the tasks stop when UITrackingRunLoopMode is active, you need to move networking code on main thread somehow.
Possible solutions:
Setup default runloop mode for your request operation.
Put connection on main thread (that’s ok, NSURLConnections are running their own threads): Find
+ (NSThread *)networkRequestThreadand make it return[NSThread mainThread]. That might be not suitable with other situations, beware locks.I am still not sure why AFNetworking is creating it’s separate network thread. To process incoming data in background? If anybody have a guess, please reply.
Also see this question.