iPhone/objC
I'm really stuck here and I could use some help, please.
Let me first explain some things:
I have an UIWebView which loads an url. once the user clicks a link - (BOOL)webView:shouldStartLoadWithRequest: navigationType: gets a message (according to the protocol). Inside this method I can decide if the url should be loaded in the webView or to do something else with it. I'm establishing an NSURLConnection so I can examine the response.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
NSLog(@" Connection established");
receivedDataFromConnection = [[NSMutableData data] retain];
}
else {
NSLog(@"Connection failed");
}
if (downloadYESorNO == YES) {
NSLog(@"Do the download");
return NO;
}
else {
NSLog(@"will show in webView");
return YES;
}
}
once the app gets an response - (void)connection:didReceiveResponse: gets an message (according to protocol) and I can analyze the response there.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSString *MIME = response.MIMEType;
NSString *appDirectory = [[NSBundle mainBundle] bundlePath];
NSString *pathMIMETYPESplist = [appDirectory stringByAppendingPathComponent:@"MIMETYPES.plist"];
NSArray *displayMIMETypes = [NSArray arrayWithContentsOfFile: pathMIMETYPESplist];
BOOL *asdf = [displayMIMETypes containsObject:MIME];
if (asdf == YES) {
downloadYESorNO =NO;
}
else {
downloadYESorNO = YES;
}
[receivedDataFromConnection setLength:0];
[connection release];
Now what I'm trying to achieve is to let - (BOOL)webView:shouldStartLoadWithRequest: wait till -(void)connection:didReceiveResponse: is ready.
I can work with sendSynchronousRequest: cause then it would download the complete file before I can examine the response.
Does anyone have an idea? Thanks in advance. or is there a better way to examine the response?