UIWebView和超时 [英] UIWebView and timeouts

查看:842
本文介绍了UIWebView和超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UIWebView 显示一些内容。在此内容中,用户可以浏览使用AJAX加载的一系列网站。这个网站上的一个步骤需要相当多的时间。由于我没有找到任何关于 UIWebView 的时间,我试图设置它的初始 NSURLRequest 它加载。



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



最佳

-f



更新



我建立了一个测试项目来验证我的理论如何 UIWebView 工作超时。这是设置:




  • 一个名为sleep.php的PHP文件,它有一个参数,我可以配置睡眠时间,直到发送结果


    b
    b p> 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

解决方案

我发现 UIWebView 同一个 NSURLRequest 一遍又一遍。所以我的答案是,不可能全局配置超时的 UIWebView


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

解决方案

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.

这篇关于UIWebView和超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆