UIWebView 和超时

发布于 2024-11-03 12:14:23 字数 1301 浏览 1 评论 0原文

我正在使用 UIWebView 来显示一些内容。在此内容中,用户可以浏览使用 AJAX 加载的一堆站点。在这个网站上迈出一步需要相当长的时间。由于我没有找到任何有关 UIWebView 超时的信息,因此我尝试在它加载的初始 NSURLRequest 上设置它。

不幸的是,这似乎没有做任何事情。我不太确定是否应该自己设置超时?我有什么遗漏的吗? UIWebView 是否会覆盖我的超时?我对此有点困惑,所以任何帮助将不胜感激。 :)

最好
–f

更新

我构建了一个测试项目来验证我关于 UIWebView 如何处理超时的“理论”。设置如下:

  • 一个名为 sleep.php 的 PHP 文件,它有一个参数,我可以使用该参数配置睡眠时间,直到它发送结果
  • 一个带有单个视图的小型 Xcode 项目,该视图是加载睡眠的 webView。 php 像这样:

    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:10]; [webView loadRequest:request];

因此,在使用秒参数时,我可以看到 UIWebView 正常工作。根据超时情况,我会得到 webViewDidFinishLoad:webView:didFailLoadWithError:

在验证了 timeoutInterval 是否如宣传的那样工作后,我引入了 proxy.php(其中有两个指向 sleep.php 的链接,配置了 5 秒和 15 秒),以查看我的请求配置是否仍然对新的有效。请求。我更改了初始 NSURLRequest 以使用 proxy.php,但保留了 10 秒的超时配置。

当我现在启动应用程序时,将显示两个链接。当我单击第一个时,它会在 5 秒后按预期加载。不幸的是,第二个链接也在 15 秒后加载。

因此,我第一次尝试重新配置 NSURLRequest 是在 webView:shouldStartLoadWithRequest:navigationType: 中更改它。再次不幸的是,Web 服务使用 AJAX,因此不会调用委托方法。

还有其他建议吗?有没有办法全局配置整个UIWebView的超时值?

最佳
–f

I'm using a UIWebView to display some content. Within this content the user can navigate through a bunch of sites which are being loaded using AJAX. One step on this sites requires quite some time. Since I didn't find anything about a timeoue for UIWebView I tried to set it on the initial NSURLRequest it loads.

Unfortunately this does not seem to do anything. I'm not quite sure if I'm supposed to set the timeout myself? Is there anything I'm missing? Does the UIWebView override my timeout? I'm a little bit confused on this so any help would be appreciated. :)

Best
–f

Update

I built a test project to verify my "theory" on how the UIWebView works with timeouts. Here is the setup:

  • a PHP file called sleep.php that has a parameter with which I can configure the time to sleep until it sends a result
  • a little Xcode project with a single view which is a webView that loads the sleep.php like this:

    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:10];
    [webView loadRequest:request];

So, while playing with the seconds parameter I could see that the UIWebView works as it should. I get either webViewDidFinishLoad: or webView:didFailLoadWithError: depending on the timeout.

After verifying that the timeoutInterval works as advertised I brought in a proxy.php (that has two links to the sleep.php configured with 5 and 15 seconds) to see if my request configuration is still valid for new requests. I changed the initial NSURLRequest to use the proxy.php but left the 10 seconds configuration for the timeout.

When I start the app now the two links are being displayed. When I click the first one it loads as expected after 5 seconds. Unfortunately, the second link loads as well after 15 seconds.

So my first attempt to reconfigure the NSURLRequest would be to change it in webView:shouldStartLoadWithRequest:navigationType:. Unfortunately again, the web service works with AJAX so the delegate method does not get called.

Any other suggestions? Is there a way to globally configure the timeout value for the whole UIWebView?

Best
–f

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

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

发布评论

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

评论(2

梦中楼上月下 2024-11-10 12:14:23

您可能有兴趣使用您自己的自定义 NSTimer 观看 UIWebView 委托 webViewDidFinishLoading

此外,如果在服务器收到响应之前遇到问题,您可以设置 NSURLConnection on requestWithURL:cachePolicy:timeoutInterval: 的超时

You might be interested in watching the UIWebView delegate webViewDidFinishLoading with your own custom NSTimer.

Also if you're having an issue till the server get you the response you can set the timeout for NSURLConnection on requestWithURL:cachePolicy:timeoutInterval:

好倦 2024-11-10 12:14:23

我发现 UIWebView 不会一遍又一遍地使用相同的 NSURLRequest 。所以我的答案是,不可能为 UIWebView 全局配置超时。

I figured out that the UIWebView does not use the same NSURLRequest over and over again. So my answer would be, that it's not possible to globally configure a timeout for the UIWebView.

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