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
if let url = URL(string: urlString) {
person.setValue(try? Data(contentsOf: url), forKey: "content_article")
}
- Data to WebView
if let savedObject = fetchedObjects?.first,
let data = savedObject.content_article as? Data,
let baseStringUrl = savedObject.content_url,
let baseURL = URL(string: baseStringUrl) {
webView.load(
data, mimeType: "text/html",
textEncodingName: "",
baseURL: baseURL
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With