Skip to content

Instantly share code, notes, and snippets.

@cvasilak
Created February 22, 2013 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvasilak/5012100 to your computer and use it in GitHub Desktop.
Save cvasilak/5012100 to your computer and use it in GitHub Desktop.
- (void)postPath:(NSString *)path
parameters:(NSDictionary *)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
NSURLRequest* request = [self requestWithMethod:@"POST" path:path parameters:parameters];
AFHTTPRequestOperation* operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
void (^timeout)(void) = ^ {
[operation cancel];
// construct "request time out" error
NSError* error = [NSError errorWithDomain:NSURLErrorDomain
code:-1001
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request timed out.",
NSLocalizedDescriptionKey, nil]];
dispatch_async(dispatch_get_main_queue(), ^{
failure(operation, error);
});
};
if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
[NSTimer scheduledTimerWithTimeInterval:_interval target:self selector:@selector(timeOut:) userInfo:[timeout copy] repeats:NO];
}
[self enqueueHTTPRequestOperation:operation];
}
// called when a timeout occurs
- (void)timeOut:(NSTimer *)timer {
void (^timeout)(void) = [timer userInfo];
timeout();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment