Search code examples
iosswiftpdfannotationspdfkit

pdfView.document?.write doesn´t work on real device. (Xcode)


@IBAction func save(_ sender: Any) {            
    let path = Bundle.main.url (forResource: "SB", withExtension: "pdf")
    pdfView.document?.write(to: path!)      
    guard let url = Bundle.main.url(forResource: "SB", withExtension: "pdf") else {
        print("File loading error!")
        return
    }
    let DOCcontroller = UIDocumentInteractionController(url: url)
    DOCcontroller.delegate = self
    DOCcontroller.presentPreview(animated: true)             
}

    func documentInteractionControllerViewControllerForPreview(_ DOCcontroller: UIDocumentInteractionController) -> UIViewController {
        return self
        }
                 
}

So my problem is that this works on XCodes simulation, but not on a real device. I dont have so much expirience in coding and it´s my first app.

Thanks for your help :D


Solution

  • You can't write to the bundle on a real device. See the accepted answer here for more details and info on where you can write files.