Mike Mike - 6 months ago 6x
Swift Question

How to save webpages and open it after clicking?

enter image description here

Attached is screenshot for my view controller. When users search on internet, how do I realize these functions?

  1. save current web page ( maybe go to another view controller after clicking "save")

  2. my idea is to save on a table view, with a brief title

  3. after clicking the title, shows contents of the whole page saved.

  4. if users reply emails on some website with attachments, they can also save the attachments (word, pdf,etc) in the app.

I initialized the web view with google. The problem is the page to be saved can be any NSURL, I have no idea how to do that.

Or you can advise some way totally different, as long as I can realize these functions.


For future reference you should include some code... but anyway, I would just set the NSURL as a string of each webpage in NSUserDefaults then call the main applications open URL method.


NSUserDefaults.standardUserDefaults.setObject("YourURL" forKey: "URLKey")

Then retrieve it like...

if let urlString = NSUserDefaults.standardUserDefaults.objectForKey("URLKey") {

let url = NSURL(string: urlString)



I wrote this code off the top of my head so it might need some tweaking but I hope it helps!