NSOperation、同步 NSURLConnection、& iPhone 上的 UIWebView

发布于 2024-08-23 15:38:46 字数 840 浏览 3 评论 0原文

我有一个奇怪的问题。设置如下:

  • 我有一个 NSOperationQueue,我将 NSOperation 子类对象添加到其中。这些使用 NSURLConnection sendSynchronousRequest 方法进行联网。据我了解,这些是完全异步的,因为它们是 NSOperations,每个都有自己的线程。
  • 如果我在没有任何后台网络操作的情况下启动我的应用程序,则将 URL 加载到 UIWebView 中就可以正常工作。
  • 如果我启动我的应用程序,并运行一些后台网络操作,将 URL 加载到 UIWebView 中会导致此错误:

    Error Domain=WebKitErrorDomain Code=102 UserInfo=0x1996d60“框架加载中断”

,并且任何后续加载 UIWebView 的尝试都会失败并出现相同的错误。

我需要注意 UIWebView 和 NSURLConnection 之间是否存在一些奇怪的交互?我的下一步是用完全异步的 NSOperation 替换同步调用,但这是一个很奇怪的错误,我想我应该询问专家。

我已将错误隔离到 NSURLConnection sendSynchronousRequest 方法。如果我从 NSOperation 调用它,UIWebView 就会崩溃。

102 错误与 WebKit 中的一些“策略已更改”错误有关,该错误在任何地方都没有记录得很差/没有记录。

有人有什么想法吗?非常感谢任何帮助!

编辑:看起来这是某种 cookie 问题。如果 Web 服务器通过后台 HTTP 请求设置 cookie,UIWebView 将无法加载的任何原因?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热血少△年 2024-08-30 15:38:46

好的,我已经弄清楚了。

显然,UIWebView 不喜欢使用全局 cookie 存储的 URLConnection HTTPRequests(甚至 ASIHTTPRequest),直到它这样做为止。所以现在我的应用程序抛出一个简单的 HTML 页面,允许 UIWebView 设置 cookie,并且每个“下游”的人显然都是一个快乐的露营者,都是通过 NSOperation 和 UIWebViews 进行 API 请求。

万岁!

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!

山田美奈子 2024-08-30 15:38:46

我不清楚你想在这里完成什么, UIWebView 将自行异步加载 NSRequest 。要检查的一件事是,通过使用 NSOperation 中的 performSelectorOnMainThread: 方法之一,确保您在代码中与 UIWebView 进行的任何交互都在主线程上。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文