Genericrich
Genericrich

Reputation: 4641

NSOperation, Synchronous NSURLConnection, & UIWebView on iPhone

I have a weird issue. Here is the setup:

and any subesequent attempts to load a UIWebView fails with the same error.

Is there some weird interaction between UIWebView and NSURLConnection that I need to be aware of? My next step is to replace the synchronous calls with a fully async NSOperation, but it is such a weird bug that I figured I would ask the experts.

I have isolated the error down to the NSURLConnection sendSynchronousRequest method. If I call this from an NSOperation, UIWebView breaks horribly.

The 102 error has to do with some "Policy Changed" error in WebKit, which is poorly/non-documented anywhere.

Anybody have any idea? Any help is greatly appreciated!

EDIT: Looks like this is a cookie issue of some kind. Any reason why UIWebView would fail to load if the web server is setting a cookie via a background HTTP Request?

Upvotes: 0

Views: 3280

Answers (2)

Genericrich
Genericrich

Reputation: 4641

OK, I have figured this out.

Apparently the UIWebView does not like URLConnection HTTPRequests (or even ASIHTTPRequest) using the global cookie store until it does. So now my app throws up a simple HTML page to allow the cookie to be set by the UIWebView, and everyone "downstream" from that is an apparently happy camper, both API requests via NSOperation, and UIWebViews.

Hooray!

Upvotes: 5

Greg Martin
Greg Martin

Reputation: 5064

I'm not clear on what you are trying to accomplish here, a UIWebView will load an NSRequest asynchronously on its own. One thing to check is to make sure any interaction you are doing in code with the UIWebView is on the main thread by using one of the performSelectorOnMainThread: methods from within your NSOperation.

Upvotes: 0

Related Questions