How to download PDF and store it locally on iPhone?

前端 未结 7 1319
时光说笑
时光说笑 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:38

    With Swift version 3.0 syntax:

    let url = NSURL(fileURLWithPath: "http://example.com/examplePDF.pdf")
    
        if let pdfData = NSData(contentsOf: url as URL) {
    
            let resourceDocPath = NSHomeDirectory().appending("/Documents/yourPDF.pdf")
    
            unlink(resourceDocPath)
    
            pdfData.write(toFile: resourceDocPath, atomically: true)
    
        }
    

提交回复
热议问题