我正在使用 AFHTTPClient 进行测试以测试后端响应。
__block id testedResponseObject = nil; [client getPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { testedResponseObject = responseObject; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { testedResponseObject = nil; }]; [client.operationQueue waitUntilAllOperationsAreFinished]; STAssertNotNil(testedResponseObject, @"");
这样做的问题是它等待所有操作完成但它不执行成功块,因为它被调度到 dispatch_get_main_queue()。有没有办法告诉 dispatch_get_main_queue() 从主队列完成它的块?