Download, Store, and View PDF in Swift

David Wu
3 min readNov 4, 2018

I’ve been working on an App that requires me to download PDF files, store it, and to view it. To accomplish the task, there are three main topics:

  • DownloadTask
  • File Management
  • PDFView

DownloadTask

To download the file from an URL, we need to use downloadTask . Since we also need to tack where the location had the task have placed our files, the observer, which is ViewController in my example, needs to conform to URLSessionDownloadDelegate .

To see where the downloaded file is located, simply inspect the location printed in the Xcode console.

After I pressed download, the file downloaded persisted less than a second, and then it was killed by the system. This behavior behaves the same on both simulator and physical machine.

File Management

Each App created in iOS has its own sandbox. Inside the sandbox, there are three main portions that iOS developers should know: Bundle Container, Data…

--

--