Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

runModalForWindow throttles http requests

I have url connection, which normally works fine

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
                                                              delegate:delegate];

But when I create a modal window, no request ever receives response:

[NSApp runModalForWindow:window];

If I comment this line out, thus creating a 'standard' window, everything works.

I tried implementing all methods from NSURLConnectionDelegate, not a single of them called.

I suspect this is something about 'run loops', but have little experience in this area. Does anybody have experience in this?

Thank you

like image 303
Nikita Rybak Avatar asked Dec 28 '22 01:12

Nikita Rybak


1 Answers

If you're targeting 10.5+, you can tell the NSURLConnection to also run in NSModalPanelRunLoopMode (the mode your current thread's runloop would be in while presenting a modal view) via

-(void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode

where aRunLoop would probably be [NSRunLoop currentRunLoop] and the mode would be NSModalPanelRunLoopMode. More info in the NSURLConnection doc.

If you're supporting earlier OSs, you may have to get creative (i.e. with multithreading). Good discussion of this issue pre-10.5 here.

like image 196
Sam Avatar answered Jan 14 '23 05:01

Sam