Reputation: 357
I am writing location based app, get weather information through API by using NSURLConnection for current/other places .At first time I sent request its working successfully. But next time I want to refer the information for same place it not working while NSURLConnection is not call the any delegate methods.
this is my code:
NSString *strs=[@"http://www.earthtools.org/timezone-1.1/" stringByAppendingString:[NSString stringWithFormat:@"%@/%@",place.latitude,place.longitude]];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:strs]];
self.reqTimeZone=[NSURLConnection connectionWithRequest:request delegate:self];
[self.reqTimeZone start];
Upvotes: 0
Views: 1019
Reputation: 11920
I assume you mean NSURLConnection
(NSConnection
doesn't exist). NSURLConnection
can only be used once. See Reusing an instance of NSURLConnection.
Another gotcha with NSURLConnection
is that it must be ran on a thread with a runloop. The main thread automatically has a run loop, but methods called on GCD and NSOperation
threads need to have the runloop created explicitly. In practice you probably don't need to run NSURLConnection
on a background thread. The download operation will not block the main thread. If you do decide to run NSURLConnection
on a run loop the easiest way to do it is probably to create an NSOperation
subclass and create the run loop inside of -main
.
Upvotes: 6