Skip to content

Instantly share code, notes, and snippets.

@marcuswestin
Created October 4, 2012 01:57
Show Gist options
  • Save marcuswestin/3831043 to your computer and use it in GitHub Desktop.
Save marcuswestin/3831043 to your computer and use it in GitHub Desktop.
NSURLConnection example
- (void)startLoading {
self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self];
if (!self.connection) {
[self.client URLProtocol:self didFailWithError:nil];
}
}
- (void)stopLoading {
[self.connection cancel];
self.connection = nil;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// Check for redirect and possibly call [self.client URLProtocol:(NSURLProtocol *) wasRedirectedToRequest:(NSURLRequest *) redirectResponse:(NSURLResponse *)]??
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.client URLProtocol:self didLoadData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self.client URLProtocolDidFinishLoading:self];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[self.client URLProtocol:self didFailWithError:error];
self.connection = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment