ios - Asynchronous calls not working in multithreaded section of code (MKOverlay canDraw) -


i can retrieve data asynchronously through nsurlconnection other part in code base except in candrawmaprect function in subclassed tileoverlayview class.

i'm modifying mapkit sample called tilemap download tiles server , overlay information on map. in candrawmaprect call function in overlay class in turn creates url , opens connection. have tested connection class , have confirmed indeed work. i've run in init functions of overlay , overlayview success. urls since can throw them in browser , show right pngs. know candrawmaprect running on multiple threads , have novice experience threads.

here connection code,

- (id)initwithstringurl: (nsstring*) url {      nslog(@"test connect init url %@", url);      self = [super init];     if (self)     {         [self loadurl:[nsurl urlwithstring:url]];         }      return self; } + (uiimage*)connectsynchronouswithurl:(nsstring*) url {     nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:url]];      nsurlresponse* response = [[nsurlresponse alloc] init];     nserror* error = [[nserror alloc] init];     nsdata* data = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error];     uiimage *image = [uiimage imagewithdata: data];      return image; } - (bool)loadurl:(nsurl *)inurl {     nsurlrequest *request = [nsurlrequest requestwithurl:inurl];     nsurlconnection *conn = [nsurlconnection connectionwithrequest:request delegate:self];      if (conn) {         receiveddata = [[nsmutabledata data] retain];         nslog(@"connection success");     } else {         nslog(@"connection failed");                 return false;     }      return true; } - (void)connection:(nsurlconnection *)conn didreceiveresponse:(nsurlresponse *)response {     nslog(@"didreceiveresponse");     [receiveddata setlength:0];  } - (void)connection:(nsurlconnection *)conn didreceivedata:(nsdata *)data {     nslog(@"didreceivedata");     [receiveddata appenddata:data]; }  - (void)connectiondidfinishloading:(nsurlconnection *)conn {     nslog(@"succeeded! received %d bytes of data", [receiveddata length]); } 

pretty standards stuff. if run code in init of tileoverlayview it'll work fine if run in candrawmaprect none of delegate functions called. suppose it's worth mentioning synchronous connection server work in candrawmaprect method. don't @ t_t

any appreciated. thank you.

from docs nsurlconnection, pretty sums up.

note these delegate methods called on thread started asynchronous load operation associated nsurlconnection object.

looks i'll needing use cfrunlooprun() , cfrunloopstop(cfrunloopgetcurrent()); keep thread alive. or find alternative making these async calls in thread.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -