本页内容
信任证书
信任证书分为两个步骤:
指定证书的信任路径(文件夹),该路径将作为信任证书时放置证书的路径,同时在检查证书是否可信时也会在该文件夹下寻找对应证书。请确保该路径是有效的,当该路径不存在或无法访问时,ComPDFKit SDK 不会自动创建信任路径文件夹。
执行信任证书的方法,证书将会被添加到信任路径下。
信任证书关键代码如下:
swift
if let url = Bundle.main.url(forResource: "filename", withExtension: "pdf") {
let document = CPDFDocument(url: url)
if let signatures = document?.signatures, let signature = signatures.first,
let signer = signature.signers.first, let certificate = signer.certificates.first {
certificate.checkCertificateIsTrusted()
let success = certificate.addToTrustedCertificates()
certificate.checkCertificateIsTrusted()
}
}
objective-c
NSURL *url = [NSURL fileURLWithPath:@"file path"];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
NSArray *signatures = [document signatures];
CPDFSignature *signature = signatures[0];
CPDFSigner *signer = signature.signers.firstObject;
CPDFSignatureCertificate * certificate = signer.certificates.firstObject;
[certificate checkCertificateIsTrusted];
BOOL success = [certificate addToTrustedCertificates];
[certificate checkCertificateIsTrusted];