我有一個類,通過NSURLConnection更新應用程序文檔目錄中的兩個.plist文件。該類充當它自己的NSURLConnection委託。當我要求單個文件時它工作正常,但當我嘗試更新兩個文件時失敗。它看起來像我應該爲每個getNewDatabase消息啓動一個新的線程?NSURLConnection委託和線程 - iPhone
- (void)getAllNewDatabases {
[self performSelectorOnMainThread:@selector(getNewDatabase:) withObject:@"file1" waitUntilDone:YES];
[self performSelectorOnMainThread:@selector(getNewDatabase:) withObject:@"file2" waitUntilDone:YES];
}
- (BOOL)getNewDatabase:(NSString *)dbName
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableString *apiString = [[NSMutableString alloc] initWithString:kAPIHost];
[apiString appendFormat:@"/%@.plist",dbName];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:apiString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *myConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self];
[apiString release];
if(myConnection)
{
//omitted for clarity here
}
[pool release];
}
//NSURLConnection delegate methods here ...
您鏈接到的博客文章已被移動 - 我相信這是它:http://www.sortedbits.com/nsurlconnection-in-its-own-thread – 2012-06-11 13:45:56