lukeredpath/libPusher — Issue #16: UIScrollView gets stuck if touched when PTURLRequestOperation executes
Author: rantav
Created: 2011-12-16 21:32:03+00:00
State: open

I noticed that there is a quirk WRT UIScrollView and the libPusher. I'm not sure whether that's actually a bug or my misusage of the lib.

What happens is that if a user scrolls a UIScrollView (or a UITableView) while [PTURLRequestOperation start] is executing, this UIScrollView gets 'stuck' and becomes unusable.

At PTURLRequestOperation.m we have:

- (void)start
{
NSAssert(URLRequest, @"Cannot start URLRequestOperation without a NSURLRequest.");

[self setExecuting:YES];

URLConnection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self startImmediately:NO];

if (URLConnection == nil) {
[self setFinished:YES];
}

// Common modes instead of default so it won't stall uiscrollview scrolling
[URLConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
[URLConnection start];

do {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
} while (!_isFinished);
}

If, by complete coincidence, the user scrolls a UIScrollView while this method is executing and keeps his fingers on it for a while, then the UIScrollView is left in a miserable state... Unusable as a matter of fact. Stuck...

I see per the comment about uiscrollview that the code is aware of this and tries to prevent it, alas, from my testing, this prevention doesn't work and it's actually easy enough if you have the right timing in your fingers to render the scrollviews unusable.

I admit I'm a complete ignorant WRT run loops et al. Of course, I may be doing something wrong elsewhere... but what I can say is that if I comment out the while loop, then the scrollviews are fine, but if the method stays as is and scrolling takes place, then the scrollview is left unusable, doesn't respond to events as it should and in short, simply unusable.

any tips?