xcode GCDWebServer 有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29345909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:53:31  来源:igfitidea点击:

What is GCDWebServer for?

iosxcodewkwebviewgcdwebserver

提问by chipbk10

I have a problem when loading the local web from WKWebView in iOS8. There are some suggestions that I should use GCDWebServer. I read through GCDWebServer, but not really understand what GCDWebServer is for on mobile application's side.

我在 iOS8 中从 WKWebView 加载本地 Web 时遇到问题。有一些建议我应该使用 GCDWebServer。我通读了GCDWebServer,但并不真正了解 GCDWebServer 在移动应用程序方面的用途。

Could you give me any practical case of using this library? Sorry for my ignorance.

你能给我任何使用这个库的实际案例吗?抱歉我的无知。

回答by Calvin Cheng

It's a webserver that you can run on your iOS device. Just like you would run a webserver on VPS or dedicated server providers.

它是一个可以在 iOS 设备上运行的网络服务器。就像您在 VPS 或专用服务器提供商上运行网络服务器一样。

This webserver that you would run and host from your iOS app will of course be available only in the network your iOS device is connected to.

您将从 iOS 应用程序运行和托管的这个网络服务器当然只能在您的 iOS 设备所连接的网络中使用。

This makes it useful for you to write client programs or scripts on other machines but connected to that network, to call your iOS app (running the GCDWebServer) to upload or download files that you so choose to store in your iOS app's sandboxes document directory for instance. Or as simple as viewing HTML or other data - plain text or json - served by GCDWebServer.

这使您可以在连接到该网络的其他机器上编写客户端程序或脚本,调用您的 iOS 应用程序(运行 GCDWebServer)来上传或下载您选择存储在您的 iOS 应用程序的沙箱文档目录中的文件。实例。或者像查看 HTML 或其他数据一样简单——纯文本或 json——由 GCDWebServer 提供。

It had nothing to do with what WKWebView. WKWebView is a 'simplified WebKit browser client' that you can implement in your iOS app to view web pages served from other webserver hosts.

它与什么 WKWebView 无关。WKWebView 是一个“简化的 WebKit 浏览器客户端”,您可以在您的 iOS 应用程序中实现它以查看从其他网络服务器主机提供的网页。

You can think of WKWebView as the complete opposite of GCDWebServer.

您可以将 WKWebView 视为 GCDWebServer 的完全相反。

回答by Vinay Hosamane

We can use GCDWebServer has a network interceptor in ios. You can intercept any HTTP requests happening inside WKWebView. For example, you can use GCDWebServer to handle caching and parallel processing for your expensive API requests. You can immediately return some cached responses and later redirect the URL to the actual destination.

我们可以使用 GCDWebServer 在 ios 中有一个网络拦截器。您可以拦截 WKWebView 内发生的任何 HTTP 请求。例如,您可以使用 GCDWebServer 来处理昂贵的 API 请求的缓存和并行处理。您可以立即返回一些缓存的响应,然后将 URL 重定向到实际目标。