私が達成しようとしているのは、注文が問題であるサーバーに2つのリクエストを送信することです。2番目のリクエストのパラメーターは、最初のリクエスト結果が返されるまで不明です。
私はすでにafnetworking2.0を使用して次のコードスニペットとして試しています
NSOperationQueue *queue=[[NSOperationQueue alloc]init];
NSMutableURLRequest*request=[NSMutableURLRequest requestWuthURL@"URLSTRING"];
// configure the request with parameters
[request setHTTPBody:JsonData];
[request setHTTPMethod:@"POST"];
AFHTTPRequestOperation* operation=[[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setComplemetionBlockWithSucess:^(AFHTTPRequestOperation* operation, id responsObject)
{
//parse the result using NSXMLParser;
NSInteger result=weakSelf.parseRule.identifier;
}
failure :^(AFHTTPRequestOperation* operation, NSError *error)
{
NSLog(@"fail");
}];
NSMutableURLRequest*secondRequest=[NSMutableURLRequest requestWuthURL@"URLSTRING"];
//Using the first request result to set the parameters in second request
[secondRequest setHTTPBody:JsonData];
[secondRequest setHTTPMethod:@"POST"];
AFHTTPRequestOperation* secondOperation=[[AFHTTPRequestOperation alloc]initWithRequest:secondRequest];
[secondOperation setComplemetionBlockWithSucess:^(AFHTTPRequestOperation* operation, id responsObject)
{
//do something
}
failure :^(AFHTTPRequestOperation* operation, NSError *error)
{
NSLog(@"fail");
}];
[secondOperation addDependency:Operation];
[queue addOPerations:@[operation,secondOperation]];
これは機能しませんでした。最初の操作結果を正しく返すことができますが、結果が返される前に 2 番目の要求パラメーター設定が実行されるという問題があります。アドバイスをいただければ幸いです。dispatch_semaphore を使用する必要がありますか? または他の提案はありますか?