【问题标题】:Check pdf is Password protected or not before iOS 11.0在 iOS 11.0 之前检查 pdf 是否受密码保护
【发布时间】:2019-07-01 03:51:18
【问题描述】:

我收到一个包含 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..
    }

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

【问题讨论】:

    标签: ios swift ios-pdfkit


    【解决方案1】:

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

    public func isLocked(fileURL: URL) -> Bool? {
        guard let document = CGPDFDocument(fileURL as CFURL) else { return nil }
        return !document.isUnlocked
    }
    

    【讨论】:

      猜你喜欢
      • 2013-03-31
      • 2016-02-19
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多