Skip to content

Instantly share code, notes, and snippets.

@n-miyo
Created February 3, 2013 14:48
Show Gist options
  • Save n-miyo/4702071 to your computer and use it in GitHub Desktop.
Save n-miyo/4702071 to your computer and use it in GitHub Desktop.
How to use asynchronous request with TPTimeoutURLConnection.
@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