ios - NSRunLoop issues with NSURLConnection and Keyboard input -


i have nsurlconnection carries out task of uploading images me. how initialize , start connection:

_connection = [[nsurlconnection alloc]                 initwithrequest:request                        delegate:self                  startimmediately:no];  [_connection scheduleinrunloop:[nsrunloop mainrunloop]                         ormode:nsdefaultrunloopmode];  [_connection start]; 

i call method somewhere else dispatch_async on own dispatch_queue. problem when image uploading , start typing in app keyboard, sometimes, freezes application. after bit of digging came understanding mainrunloop handles input requests such keyboard button press. wanted know if right , causing problem freezing app. regarding issue appreciated. thank in advance.

p.s: tried running connection on currentrunloop doesnt work unless manually start currentrunloop.

the asynchronous nsurlconnection meant run inside runloop. have 2 choices: use main thread/main runloop or spawn thread , start separate runloop there. in later case, you'd need use [nsrunloop currentrunloop] instead of [nsrunloop mainrunloop].

i recommend going main thread/main runloop. asynchronous nsurlconnection efficient, it's no problem having lot of them run on main thread. won't notice performance problems unless expensive stuff in delegate methods.

so run code on main thread , should fine.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -