1

我正在使用 PDFKit 更改 iOS 应用程序中 PDF 文件的注释。当我尝试保存文件时,我没有收到任何错误并且路径看起来正确,打印语句返回 file:///var/mobile/Containers/Data/Application/6A9CF20F-7785-43F8-8015-C1D547A6236A/Documents/测试pdf.pdf。但是我无法使用 iPhone 上的文件找到新的 PDF 文件。请参阅下面的保存功能代码:

func makethepdf() {
    let pdfView = PDFView()
    @ObservedObject var globalString = GlobalString()
    // Document
    guard let url = Bundle.main.url(forResource: "template", withExtension: "pdf") else {
        return
    }
    guard let document = PDFDocument(url: url) else {
        return
    }
    pdfView.document = document
    for index in 0..<document.pageCount {
        if let page = document.page(at: index) {
            let annotations = page.annotations
            for annotation in annotations {
                if annotation.fieldName == "Name" {
                    annotation.setValue(globalString.ownername, forAnnotationKey: .widgetValue)
                }
            }
        }
    }
    let paths = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
    let documentsDirectory = paths
    let savefile = documentsDirectory.appendingPathComponent("testpdf.pdf")
    print (savefile.absoluteString)
    if !document.write(to: savefile) {
        print ("file not saved")
    }
}

解决方案:如果您想在 Apple 的 Files App 中公开您的 App 文档文件,您需要在 info plist 文件中包含“Supports Document Browser”键并将其设置为 YES

4

0 回答 0