を管理するので、最初に私のセットアップの2つの要求:次に私は2つの異なったKMLファイルから2つの非同期リクエストをしたい2 NSURLConnection
AResponseData = [[NSMutableData alloc] init];
BResponseData = [[NSMutableData alloc] init];
:
NSString *server1URL = [NSString stringWithFormat:...];
NSMutableURLRequest *firstRequest =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:server1URL]];
[firstRequest setHTTPMethod:@"GET"];
NSURLConnection *AConnection = [NSURLConnection connectionWithRequest:firstRequest delegate:self];
NSString *server2URL = [NSString stringWithFormat:...];
NSMutableURLRequest *secondRequest =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:server2URL]];
[secondRequest setHTTPMethod:@"GET"];
NSURLConnection *BConnection = [NSURLConnection connectionWithRequest:secondRequest delegate:self];
は、それから私は、私が使用するNSMutableData
を初期化、私はthis記事を参照して、このでした:
connectionToInfoMapping = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionaryAddValue(connectionToInfoMapping, AConnection, [NSMutableDictionary dictionaryWithObject:AResponseData forKey:@"receivedData"]);
CFDictionaryAddValue(connectionToInfoMapping, BConnection, [NSMutableDictionary dictionaryWithObject:BResponseData forKey:@"receivedData"]);
[OK]を、そしてそこにいる代表者:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
const NSMutableDictionary *connectionInfo = CFDictionaryGetValue(connectionToInfoMapping, connection);
[[connectionInfo objectForKey:@"receivedData"] appendData:data];
}
だからこれで、私は、データが接続に一致する正しいNSMutableDataに追加取得することができます。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
で、私は「これが終わったら、これで終わり、これをやりなさい」と欲しいと思います。私の質問はどうしたらいいですか?
私はNSURLConnectionをサブクラス化し、キーまたはで各要求を識別するためのタグのような項目を追加し、あなたがリクエストを初期化するinitメソッドをオーバーライドすることを利用してお勧めします。これは私が現在複数の非同期接続が必要な私のアプリでやっていることです。私は[this](http://blog.emmerinc.be/index.php/2009/03/02/custom-nsurlconnection-class-with-tag/)と[this](http://blog.emmerinc。/index.php/2009/03/15/multiple-async-nsurlconnections-example /)を使用して、アプリケーションの問題を解決してください。 – Bourne