views:

1030

answers:

2

Hello Gentlebeings,

I have a weird issue. Here is the setup:

  • I have a NSOperationQueue which I add NSOperation subclass objects to. These do networking using NSURLConnection sendSynchronousRequest method. As I understand it, these are completely asynchronous, since they are NSOperations which each get their own thread.
  • If I launch my app WITHOUT any background networking operations, loading a URL into a UIWebView works just fine.
  • If I launch my app, and run some background networking operations, loading a URL into a UIWebView results in this error:

    Error Domain=WebKitErrorDomain Code=102 UserInfo=0x1996d60 "Frame load interrupted"

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?

A: 

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.

Greg Martin
The NSOperations doing the background networking (polling an API for data) are completely independent of the UIWebViews. This is the issue. There IS no interaction betwixt the two, which is why the bug is so maddening.
Genericrich
+2  A: 

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!

Genericrich