1

我得到一个包含 pdf 文档的 url。

如果密码受到保护,我需要向用户询问密码。

在 iOS 11.0 之后使用 PDFkit 也可以做到这一点。

    if #available(iOS 11.0, *) {
                    if let pdfDocument = PDFDocument(url: url) {

                        print(pdfDocument.isEncrypted) 
                        print(pdfDocument.isLocked) 

                        if pdfDocument.isEncrypted {
                            // Its password protected
                        }
                    }
    }
    else {

    // Earlier versions..
    }

有没有办法做到这一点?尽可能不使用任何第三方

4

1 回答 1

1

对于 iOS 10 或更早版本,您应该使用 CGPDFDocument:

public func isLocked(fileURL: URL) -> Bool? {
    guard let document = CGPDFDocument(fileURL as CFURL) else { return nil }
    return !document.isUnlocked
}
于 2019-02-07T04:53:38.617 回答