1

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?

Krishnan Sriram
  • 5,037
  • 5
  • 21
  • 31

2 Answers2

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
-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