Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>through a lot of searching around and asking friends i managed to find the code and though that i would share it with everyone</p> <p><strong>Objective-C</strong></p> <pre><code>- (void) cacheFile { //Create the file/directory pointer for the storage of the cache. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); self.dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"cache.html"]; //Check to see if a file exists a the location if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) { //Code for customising when the cache reloads would go here. } else { //If no file exists write the html cache to it //Download and write to file NSURL *cacheUrl = [NSURL URLWithString:@"INSERT WEB URL HERE"]; NSData *cacheUrlData = [NSData dataWithContentsOfURL:cacheUrl]; [cacheUrlData writeToFile:dataPath atomically:YES]; } //Run the load web view function. [self loadWebView]; } - (void) loadWebView { //Load up the web view from the cache. [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:dataPath]]]; } </code></pre> <p><strong>Swift 3</strong></p> <pre><code>func cacheFile() { //Create the file/directory pointer for the storage of the cache. let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) guard let dataPath = paths.first?.appending("cache.html") else { return } //Check to see if a file exists a the location if FileManager.default.fileExists(atPath: dataPath) { //Code for customising when the cache reloads would go here. } else if let cacheUrl = URL(string: "INSERT WEB URL HERE") { //If no file exists write the html cache to it //Download and write to file do { let cacheUrlData = try Data(contentsOf: cacheUrl) try cacheUrlData.write(to: URL(fileURLWithPath: dataPath), options: Data.WritingOptions.atomic) } catch { print("Problem with cacheUrlData") } } //Run the load web view function. loadWebView(dataPath: dataPath) } func loadWebView(dataPath: String) { webView.loadRequest(URLRequest(url: URL(fileURLWithPath: dataPath))) } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload