views:

1195

answers:

1

Hi! Help is highly appreciated. I'm stuck here:

I need to examine a response before I start loading an URL in my UIWebView. However a synchronous NSURLConnection will first download the data and then let me access the response, which is bad.

An asynchronous NSURLConnection will let me examine the response before any data is received but I only can only examine the response in the delegate method connection:didReceiveResponse: . But then I would have to tell my webView's delegete method (webView:shouldStartLoadWithRequest:navigationType:) to wait till the the response is there. Because both delegates are in the main thread (do they have to be? I guess so) I can't simply use NSCondition to stop webView's delegate (cause that means stopping the main thread).

Does anyone have an idea on how to solve this problem?

Thanks in advance.

A: 

Read all the data using NSConnection, then load it into the UIWebView using -loadData:MIMEType:textEncodingName:baseURL:.

Rob Napier
would be nice, but I can't simply load a xx MB file just to find out its mime type. that's why I need to work with the response.
Yllier
You're going to load the xx MB file one way or the other (either with NSURLConnection or UIWebView; it's all you). What are you going to do with the knowledge of its mime type before handing it off to UIWebView? Perhaps there's a more problem-specific (rather than solution-specific) part of the question that you've left out?
Rob Napier
thanks for trying to help.I want to decide inside my webView:shouldStartLoadWithRequest:navigationType: delegate if I want to download from that URL or show it in webView (see if the MIME type is html/php or another type of file). the important part is that I need to analyze the request before webView:shouldStartLoadWithRequest:navigationType: is finished. so I need to find a way to put the webView delegate on hold till the response can be examined (without downloading all data, cause I want to ask the user if he wants to download a file) (like a real browser)
Yllier