Created
February 22, 2013 09:36
-
-
Save cvasilak/5012100 to your computer and use it in GitHub Desktop.
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)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