Reputation: 11567
I'm getting a url which contains an pdf document.
I need to ask the user for the password if it is protected.
The same is able to do after iOS 11.0 using 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..
}
Is there any way to do this? without using any third party if possible
Upvotes: 2
Views: 1418
Reputation: 1679
For iOS 10 or earlier, you should use CGPDFDocument:
public func isLocked(fileURL: URL) -> Bool? {
guard let document = CGPDFDocument(fileURL as CFURL) else { return nil }
return !document.isUnlocked
}
Upvotes: 3