Created
February 3, 2013 14:48
-
-
Save n-miyo/4702071 to your computer and use it in GitHub Desktop.
How to use asynchronous request with TPTimeoutURLConnection.
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
@interface FooDelegate : TPURLConnectionDelegate | |
//... | |
@end | |
@implementation FooDelegate | |
- (void)connection:(NSURLConnection *)connection | |
didFailWithError:(NSError *)error | |
{ | |
[super connection:connection didFailWithError:error]; | |
// my code... | |
} | |
- (void)connectionDidFinishLoading:(NSURLConnection *)connection | |
{ | |
[super connectionDidFinishLoading:connection]; | |
// my code... | |
} | |
@end | |
@implementation MyObject | |
@property FooDelegate *delegate; | |
- (id)init | |
{ | |
self = [super init]; | |
if (self) { | |
self.delegate = [FooDelegate new]; | |
} | |
return self; | |
} | |
- (void)run | |
{ | |
NSURLRequest *r = | |
[NSMutableURLRequest | |
requestWithURL:[NSURL URLWithString:@"http://example.com/"] | |
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData | |
timeoutInterval:10.0f]; | |
[r setHTTPBody:[@"x" dataUsingEncoding:NSUTF8StringEncoding]]; | |
id con = [[TPURLConnection alloc] | |
initWithRequest:r | |
timeoutInterval:10.0 /* r.timeoutInterval は使えない */ | |
delegate:self.delegate]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment