Use local resources in WKWebview

1.6k views Asked by At

How do I make WKWebview use local .js, .css and/or local image files, in place of remote files, in order to make the web page load faster. Also, I noticed NSURLProtocol methods (when implemented through register class) do not get called when WKNavigationDelegate methods are implemented, any idea on why?

2

There are 2 answers

1
Krishnan Sriram On BEST ANSWER

After going through a lot of documentation, I realized/learnt that I'll not be able to track URLs if I use WKWebviews. I have to resort to UIWebView for the moment.

2
Clement Prem On

In iOS 9 API there is a new method for loading local resource

/*! @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?