Objective c 我想使用AFN网络返回块内的数据
我有一个使用AFJSONRequestOperation的函数,我希望只在成功后返回结果。你能给我指一下正确的方向吗?我对区块和AFN网络仍然有点一无所知。如果你发布了你的代码会更好 使用Objective c 我想使用AFN网络返回块内的数据,objective-c,Objective C,我有一个使用AFJSONRequestOperation的函数,我希望只在成功后返回结果。你能给我指一下正确的方向吗?我对区块和AFN网络仍然有点一无所知。如果你发布了你的代码会更好 使用\u块可以在块内使用变量 __block NSString *msg; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionB
\u块
可以在块内使用变量
__block NSString *msg;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[hud hide:YES];
NSLog(@"Success %@", operation.responseString);
NSDictionary *message = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",message);
msg = message
ALERT(@"Posted", message[@"message"]);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", operation.responseString);
NSLog(@"%@",error);
}];
[operation start];
长时间调用该方法后,它不会进入阻塞状态。它会进入成功阻塞状态。我真的不明白你想要什么。成功是在请求完成时。该块的目的是使其内部的代码独立运行。请清楚地告诉我你的要求,以便我们能提供帮助。我的意思是当我们使用AFNetworking调用API时,我想立即执行成功阻止,我的意思是我想发送同步请求。