NSURLRequest won't fire while UIScrollView is scrolling NSURLRequest won't fire while UIScrollView is scrolling objective-c objective-c

NSURLRequest won't fire while UIScrollView is scrolling


The NSURLRequest only manages the request, not the actual connection.

Touch events such as scrolling will place the run loop into NSEventTrackingRunLoopMode. By default, an NSURLConnection is scheduled to only execute in NSDefaultRunLoopMode. So while in NSEventTrackingRunLoopMode, NSDefaultRunLoopMode is blocked.

Good news is that you can schedule additional modes for an NSURLConnection, such as NSRunLoopCommonModes.

connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];[connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];[connection start];


I've figured out the hard way that if you call startImmediately:YES or ommit this parameter second line is completely useless. So be sure to follow the exact pattern provided by @tidwall.

Here's also a swift example:

self.connection = NSURLConnection(request: self.request, delegate: self, startImmediately:false)self.connection?.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes)self.connection?.start()