使用AFHTTPSessionOperation时超时 [英] Timed Out while using AFHTTPSessionOperation
本文介绍了使用AFHTTPSessionOperation时超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我为什么我的通话超时吗?我的应用程序刚刚挂在那里,从未执行以下代码的成功:^(NSURLSessionTask *操作,id响应)部分。
Can anybody tell me why my call "timed out"? My app just hangs there, the success:^(NSURLSessionTask* operation, id response) section of the folowing code was never executed.
return [self beginRequestController:@"myController" action:@"myAction" parameters:parameters
success:^(NSURLSessionTask* operation, id response)
{
NSLog(@"This is NOT being called --->>>: %@", response);
} failure:^(NSURLSessionTask* operation, NSError* error)
{
//Handle the error
}];
- (NSOperation*) beginRequestController:(NSString*)controller action: (NSString*)action parameters:(NSDictionary*)parameters success: (RequestSuccess)success failure:(RequestFailure)failure
{
NSOperation *operation = [AFHTTPSessionOperation operationWithManager:manager HTTPMethod:@"POST" URLString:urlString parameters:parameters uploadProgress:nil downloadProgress: nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"Reponse --->>>: %@", responseObject );
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error --->>>: %@", error);
}];
[self.operationQueue addOperation:operation];
return operation;
}
推荐答案
您正在将块传递给 beginRequestController
,但是该方法对它们没有任何作用。您要调用这些块。例如,
You're passing blocks to beginRequestController
, but that method doesn't do anything with them. You want to call those blocks. E.g.
- (NSOperation *)beginRequestController:(NSString *)controller action:(NSString *)action parameters:(NSDictionary *)parameters success:(RequestSuccess)success failure:(RequestFailure)failure {
NSOperation *operation = [AFHTTPSessionOperation operationWithManager:manager HTTPMethod:@"POST" URLString:urlString parameters:parameters uploadProgress:nil downloadProgress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"Response --->>>: %@", responseObject);
if (success)
success(task, responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error --->>>: %@", error);
if (failure)
failure(task, error);
}];
[self.operationQueue addOperation:operation];
return operation;
}
或更简单:
- (NSOperation *)beginRequestController:(NSString *)controller action:(NSString *)action parameters:(NSDictionary *)parameters success:(RequestSuccess)success failure:(RequestFailure)failure {
NSOperation *operation = [AFHTTPSessionOperation operationWithManager:manager HTTPMethod:@"POST" URLString:urlString parameters:parameters uploadProgress:nil downloadProgress: nil success:success failure:failure];
[self.operationQueue addOperation:operation];
return operation;
}
这篇关于使用AFHTTPSessionOperation时超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文