使用 AFHTTPSessionOperation 时超时
Timed Out while using AFHTTPSessionOperation
谁能告诉我为什么打电话给 "timed out"?我的应用程序只是挂在那里,成功:^(NSURLSessionTask* 操作,id 响应)以下代码的部分从未执行过。
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
,但该方法对它们没有任何作用。你想调用那些块。例如
- (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;
}
谁能告诉我为什么打电话给 "timed out"?我的应用程序只是挂在那里,成功:^(NSURLSessionTask* 操作,id 响应)以下代码的部分从未执行过。
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
,但该方法对它们没有任何作用。你想调用那些块。例如
- (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;
}