NSURLConnection
とその委任方法を検討することを検討してください。これらを使用して、ダウンロードの状態を確認することができます。
@interface
...
NSURLConnection *connectionInProgress;
NSData *googleRequestResponseData;
NSURL *googleURL;
...
@implementation
...
- (void) setUpRequest {
googleURL = [[NSURL URLWithString:@"http://www.google.com/"] retain];
googleRequestResponseData = [[NSMutableData data] retain];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];
connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
#pragma mark NSURLConnection delegate methods
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[googleRequestResponseData appendData:data];
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[web_screen loadData:googleRequestResponseData MIMEType:@"application/octet-stream" textEncodingName:@"utf-8" baseURL:googleURL];
NSString *js_result = [web_screen stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('input')[1].value='test';"];
NSLog (js_result);
[googleURL release];
[googleRequestResponseData release];
[connectionInProgress release];
connectionInProgress = nil;
}
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog (@"Connection failed to load data from Google!");
[googleURL release];
[googleRequestResponseData release];
[connectionInProgress release];
connectionInProgress = nil;
}
あるいは、非同期ダウンロード(具体的には、ASINetworkQueue
を参照)に簡略化されたアプローチを含むベンCopseyのASIHTTPRequestラッパーを、チェックアウト。
要求のダウンロードが完了すると、ASINetworkQueue
を使用して(たとえば、JavaScriptコードを実行するために)選択した方法を実行できます。
これは間違いなく問題です。 –