Created
October 4, 2012 01:57
-
-
Save marcuswestin/3831043 to your computer and use it in GitHub Desktop.
NSURLConnection example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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