How to download PDF and store it locally on iPhone?

前端 未结 7 1307
时光说笑
时光说笑 2020-11-30 19:51

I am able to successfully view a PDF from a website. I want to be able to download that PDF to the device, then access that file locally.

When the app is opened, it

7条回答
  •  爱一瞬间的悲伤
    2020-11-30 20:28

    I found a swift version for it:

    let url = "http://example.com/examplePDF.pdf"
    if let pdfData = NSData(contentsOfURL: url) {
        let resourceDocPath = NSHomeDirectory().stringByAppendingString("/Documents/yourPDF.pdf")
        unlink(resourceDocPath)
        pdfData.writeToFile(resourceDocPath, atomically: true)
    }
    

    Just remember to save the path file and you'll be able to fetch it whenever you need it.

提交回复
热议问题