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?
Asked
Active
Viewed 1,540 times
2 Answers
3
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?

Clement Prem
- 3,112
- 2
- 23
- 43
-
Thanks for looking into it. I will need the solution to work in ios7 & 8, per requirement :( – Krishnan Sriram Jun 11 '15 at 11:33
-
3The question is about using cached css/jss assets to speed up navigation for remote websites. This answer is instead about navigating to a local webpage on device. – Gautham Badhrinathan Dec 14 '15 at 18:30
-3
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.

Krishnan Sriram
- 5,037
- 5
- 21
- 31
-
Why do you think you cannot track URLs using WKWebView? Take a look at [WKNavigationDelegate](https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKNavigationDelegate_Ref/) – Akshay Rangnekar Jan 22 '16 at 10:09