I am initialising up an NSURLConnection with a request and have both didFailWithError and didReceiveData setup.
The application will successfully use both these methods for any situations wear I want it to use them but if you switch to offline mode whilst in the app, didFailWithError get called for any delegate I have set up even though I no longer need them.
If a real user lost their connection I don't want these methods to execute.
-(void) RequestExample
{
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:someRequest delegate:self];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[self NotifyObserversOfFailure];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[self NotifyObserversOfSuccess];
}
Someone suggested checking the error code in these methods but that doesn't feel like a fix.
Somewhere else I have read is to nil the connection but where would I put this because putting it in the didReceiveData
method doesn't work.
Thanks for your help