How to save UIWebView contents for offline display?

I use Xcode 7.2 and Swift to create an iOS application, in this application I show the contents of my website, however, if I were offline, the content would not be shown. So I want to cache the webpage and display it offline.

After I declared everything, I use the following code:

    var URLPATH="http://google.com"

    let requestURL = NSURL(string: URLPATH)

    let request = NSURLRequest(URL: requestURL!)

    WB.loadRequest(request)
+4
source share
1 answer
  • HTML for data

    let urla = URL (string: obj.1 ["content_url"]. stringValue)

    if urla != nil {
    
    person.setValue(try? Data(contentsOf: urla!), forKey: "content_article")
    

    }

    1. Data for WebView

let data = self.fetchedResultsController.fetchedObjects? .first? .content_article

 let baseUrl = self.fetchedResultsController.fetchedObjects?.first?.content_url
    webView.load(data! as Data, mimeType: "text/html", textEncodingName: "", baseURL: URL(string: baseUrl!)

!)

0
source

Source: https://habr.com/ru/post/1623415/


All Articles