简体   繁体   English

为什么iOS UIWebView loadRequest方法不返回值?

[英]Why does the iOS UIWebView loadRequest method not return a value?

In iOS, the Xcode/Swift method to load an HTTP request is void, and returns no value. 在iOS中,用于加载HTTP请求的Xcode / Swift方法无效,并且不返回任何值。

Why not return the response code? 为什么不返回响应代码? For example, on a successful page request, return 200; 例如,在成功的页面请求中,返回200;否则,返回200。 on a not found, return 404. 在未找到的情况下,返回404。

I know that the status variable can be pulled from the header in the WebViewDidFinishLoad Method (ref link below), but it seems that a return code directly from the loadRequest method would make sense. 我知道可以从WebViewDidFinishLoad方法(下面的参考链接)的标头中提取status变量,但是直接从loadRequest方法返回的代码似乎有意义。

EDIT: Updated clip from documentation 编辑:从文档更新剪辑

在此处输入图片说明

Get the http response code from every UIWebView request 从每个UIWebView请求获取http响应代码

Ah, so you meant loadRequest ? 嗯,所以你是说loadRequest吗? As you can see from the docs you've quoted, it's asynchronous, so it will almost certainly return before the request has completed, so it can't return the response code as the response hasn't happened yet. 从引用的文档中可以看到,它是异步的,因此几乎可以肯定会在请求完成之前返回它,因此由于响应尚未发生,因此它无法返回响应代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM