Ok this is annoying me. I have the following code:
weatherAddress = [NSString stringWithFormat:@"http://google.com"];
weatherUrl = [NSURL URLWithString:weatherAddress];
weatherContents = [NSString stringWithContentsOfURL:weatherUrl encoding:NSASCIIStringEncoding error:nil];
if ([viewer.request.URL.relativeString isEqualToString:weatherContents]) {
//do stuff
}
but when it runs, it sometimes throws a bad access. When i say sometimes I mean usually 50% of the time. What am I doing wrong?
How about this, assuming weatherContents is defined in the class:
then create a method called
checkIfWeatherReceivedlike so:I really don’t like using stuff that will lock up your interface if your connection drops out, so I would refrain from just “making it wait” or something. This will check every half a second if the weather data has been grabbed. If you want it to check faster just change the TimeInterval. You may want it to be really really fast like .01 or something if you are not finding very much delay in the data. You should also think about what will happen if the connection is lost and you never get the data, unless you have already accounted for that. I have not tested this, but I think it should work out, assuming all of your pieces are part of the class and not local to a method. I would also probably break out the actual work from
checkIfWeatherReceivedinto another method, instead of just placing it in theif(weatherContents)true area.