Created
January 9, 2014 03:10
-
-
Save bugcloud/8328824 to your computer and use it in GitHub Desktop.
[AFNetworking] AFHTTPRequestOperationManagerを使うときにタイムアウト時間を設定する ref: http://qiita.com/bugcloud/items/80ea9a4da4624ef2391f
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
#import "AFHTTPRequestOperationManager+Timeout.h" | |
@implementation AFHTTPRequestOperationManager (TimeoutCategory) | |
- (AFHTTPRequestOperation *)GET:(NSString *)URLString | |
parameters:(NSDictionary *)parameters | |
timeoutInterval:(NSTimeInterval)timeoutInterval | |
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success | |
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure | |
{ | |
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"GET" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters]; | |
[request setTimeoutInterval:timeoutInterval]; | |
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure]; | |
[self.operationQueue addOperation:operation]; | |
return operation; | |
} | |
- (AFHTTPRequestOperation *)POST:(NSString *)URLString | |
parameters:(NSDictionary *)parameters | |
timeoutInterval:(NSTimeInterval)timeoutInterval | |
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success | |
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure | |
{ | |
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters]; | |
[request setTimeoutInterval:timeoutInterval]; | |
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure]; | |
[self.operationQueue addOperation:operation]; | |
return operation; | |
} | |
@end |
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
#import "AFHTTPRequestOperationManager+Timeout.h" | |
@implementation Sample | |
+ (void)fetchSamples:(NSDictionary *)params | |
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success | |
failed:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failed | |
{ | |
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | |
[manager GET:@“SOME_PATH” | |
parameters:@{} | |
timeoutInterval:10.0f | |
success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
success(operation, responseObject); | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
failed(operation, error); | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment