I'm using Xcode 7.2 and Swift to create an iOS app, on this app I display the content of my website, however if I was offline the content will not be shown. So I want to cache the webpage and display for offline.
After I declared everything I'm using the following code :
var URLPATH="http://google.com"
let requestURL = NSURL(string: URLPATH)
let request = NSURLRequest(URL: requestURL!)
WB.loadRequest(request)
HTML to Data
let urla = URL(string: obj.1["content_url"].stringValue)
if urla != nil { person.setValue(try? Data(contentsOf: urla!), forKey: "content_article")}
- Data to 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!)
!)
来源:https://stackoverflow.com/questions/34676149/how-to-save-uiwebview-content-for-offline-display