我正在应用程序中实现URLProtocol。URLProtocol未初始化
import Cocoa
class MyURLProtocol: URLProtocol {
override init(request: URLRequest, cachedResponse: CachedURLResponse?, client: URLProtocolClient?) {
super.init(request: request, cachedResponse: cachedResponse, client: client)
}
override class func canInit(with request: URLRequest) -> Bool {
return true
}
override class func canonicalRequest(for request: URLRequest) -> URLRequest {
return request
}
override func startLoading() {
print("loading")
}
}
虽然canInit(with request: URLRequest)
总是返回true,既不init(…)
也不canonicalRequest(…)
也不startLoading()
被调用。
URLProtocol.registerClass
为MyURLProtocol
在AppDelegate
我不知道该怎么做叫willFinishLaunching
。昨天,代码至少调用了函数。
感谢您的帮助。
不,我只在WKWebView中加载URLRequest。 – Sandro
我需要在我的应用程序中处理不同的url模式 – Sandro
我还实现了WKNavigationDelegate和func webView(_ webView:WKWebView,didFailProvisionalNavigation导航:WKNavigation !, withError错误:错误)被调用时出现不受支持的url错误。 – Sandro