Ios WKWebView拦截http/https请求
我的android版本的应用程序使用WebView,并依靠Ios WKWebView拦截http/https请求,ios,swift,wkwebview,Ios,Swift,Wkwebview,我的android版本的应用程序使用WebView,并依靠shouldInterceptRequest方法提供运行时下载的svg资源,这些资源由http/https从WebView请求。 希望在ios版本的应用程序上迁移此类行为。然而,WKWebView似乎没有提供拦截http/https请求的工具。鉴于必须使用WKWebView,可以采用哪些策略在ios上实现类似的行为?最终我使用了 我已将本地Web服务器设置为: let webServer: GCDWebServer = GCDWebSer
shouldInterceptRequest
方法提供运行时下载的svg资源,这些资源由http/https
从WebView请求。
希望在ios版本的应用程序上迁移此类行为。然而,
WKWebView
似乎没有提供拦截http/https
请求的工具。鉴于必须使用WKWebView
,可以采用哪些策略在ios上实现类似的行为?最终我使用了
我已将本地Web服务器设置为:
let webServer: GCDWebServer = GCDWebServer()
webServer.addGETHandler(forBasePath: "/", directoryPath: baseResourcePath, indexFilename: "index.html", cacheAge: 0, allowRangeRequests: true)
然后提供位于index.html包含目录之外的文件
必须附加自定义get处理程序:
webServer.addHandler(forMethod: "GET", pathRegex: "images", request: GCDWebServerRequest.self) { request in
let fileName = request.path.components(separatedBy: "/images/")[1]
var documentsURL = FileManager.default.urls(for: .docmentDirectory, in: .userDomainMask)[0]
documentsURL.appendPathComponent("images/\(fileName)")
let response = GCDWebServerFileResponse(file: documentsURL.path)
return response
}