在WKWebview中使用本地资源

Use local resources in WKWebview

如何让 WKWebview 使用本地 .js, .css and/or 本地图像文件代替远程文件,以加快网页加载速度。 另外,我注意到 NSURLProtocol 方法(当通过寄存器 class 实现时)在实现 WKNavigationDelegate 方法时不会被调用,知道为什么吗?

在iOS9API中有一个加载本地资源的新方法

/*! @abstract Navigates to the requested file URL on the filesystem. @param URL The file URL to which to navigate. @param readAccessURL The URL to allow read access to. @discussion If readAccessURL references a single file, only that file may be loaded by WebKit. If readAccessURL references a directory, files inside that file may be loaded by WebKit. @result A new navigation for the given file URL. */

@available(iOS 9.0, *)
func loadFileURL(URL: NSURL, allowingReadAccessToURL readAccessURL: NSURL) -> WKNavigation?

在查看大量文档后,我 realized/learnt 如果我使用 WKWebviews,我将无法跟踪 URL。我暂时不得不求助于 UIWebView。