Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
172 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ConnectionDelegate.h | ||
// iphone-harvest | ||
// | ||
// Created by vickeryj on 1/14/09. | ||
// Copyright 2009 Joshua Vickery. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface ConnectionDelegate : NSObject { | ||
|
||
NSMutableData *data; | ||
NSURLResponse *response; | ||
BOOL done; | ||
NSError *error; | ||
NSURLConnection *connection; | ||
|
||
} | ||
|
||
- (BOOL) isDone; | ||
- (void) cancel; | ||
|
||
@property(nonatomic, retain) NSURLResponse *response; | ||
@property(nonatomic, retain) NSMutableData *data; | ||
@property(nonatomic, retain) NSError *error; | ||
@property(nonatomic, retain) NSURLConnection *connection; | ||
|
||
@end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// ConnectionDelegate.m | ||
// iphone-harvest | ||
// | ||
// Created by vickeryj on 1/14/09. | ||
// Copyright 2009 Joshua Vickery. All rights reserved. | ||
// | ||
|
||
#import "ConnectionDelegate.h" | ||
|
||
|
||
@implementation ConnectionDelegate | ||
|
||
@synthesize response, data, error, connection; | ||
|
||
- (id) init | ||
{ | ||
self = [super init]; | ||
if (self != nil) { | ||
self.data = [NSMutableData data]; | ||
done = NO; | ||
} | ||
return self; | ||
} | ||
|
||
- (BOOL) isDone { | ||
return done; | ||
} | ||
|
||
- (void) cancel { | ||
[connection cancel]; | ||
self.response = nil; | ||
self.data = nil; | ||
self.error = nil; | ||
done = YES; | ||
} | ||
|
||
#pragma mark NSURLConnectionDelegate methods | ||
- (NSURLRequest *)connection:(NSURLConnection *)aConnection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response { | ||
return request; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { | ||
[[challenge sender] useCredential:[challenge proposedCredential] forAuthenticationChallenge:challenge]; | ||
} | ||
- (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { | ||
done = YES; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse { | ||
self.response = aResponse; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)someData { | ||
[data appendData:someData]; | ||
} | ||
|
||
- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection { | ||
done = YES; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error { | ||
done = YES; | ||
} | ||
|
||
//don't cache resources for now | ||
- (NSCachedURLResponse *)connection:(NSURLConnection *)aConnection willCacheResponse:(NSCachedURLResponse *)cachedResponse { | ||
return nil; | ||
} | ||
|
||
|
||
#pragma mark cleanup | ||
- (void) dealloc | ||
{ | ||
[data release]; | ||
[response release]; | ||
[error release]; | ||
[connection release]; | ||
[super dealloc]; | ||
} | ||
|
||
|
||
@end |
This file contains 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