5

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)
2
  • Hi, did you solve this problem? It would really help me. Commented May 2, 2016 at 18:53
  • I would like an answer to this as well. Need to do the same, but it's horrible finding a good repo. Commented May 19, 2016 at 14:51

1 Answer 1

1
  1. HTML to Data
if let url = URL(string: urlString) {
   person.setValue(try? Data(contentsOf: url), forKey: "content_article")
}
  1. 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
  )
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.