Skip to content

向iOS添加许可密钥

如果您还没有获取许可证密钥,请查看如何获取许可证密钥

ComPDFKit PDF SDK 目前支持两种许可证密钥验证方式:在线认证和离线认证。

了解关于:

复制许可证密钥

获取许可证密钥之后,根据以下步骤将其应用到您自己的项目:

  1. 在您收到的邮件中,找到包含许可证密钥的XML文件。

  2. 直接手动将XML文件拖动到项目中即可,如下图所示:

选择文件的选项勾选"Copy items if needed"和"Create groups"即可,如下图所示:

应用许可证密钥

在使用任何 ComPDFKit PDF SDK 类之前,必须执行以下操作将许可证用于应用:

  1. AppDelegate.swift 中导入头文件 ComPDFKit
  2. 通过上一步获取的在线认证XML,使用下面方法初始化
  3. 初始化许可证, 需要在在 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool 中调用,代码如下:
swift
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  // 在这里设置您的在线许可证密钥。ComPDFKit 是商业软件。
  // 每个 ComPDFKit 许可证都绑定到特定的应用程序包标识符。
  // com.compdfkit.pdfviewer
    
    guard let xmlFliePath = Bundle.main.path(forResource: "license_key_ios", ofType: "xml") else {
         return true
    }
    
    CPDFKit.verify(withPath: xmlFliePath, completionHandler: { code, message in
        print("Code: \(code), Message:\(String(describing: message))")
    })
}
objective-c
#import <ComPDFKit/ComPDFKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // 在这里设置您的在线许可证密钥。ComPDFKit 是商业软件。
  // 每个 ComPDFKit 许可证都绑定到特定的应用程序包标识符。
  // com.compdfkit.pdfviewer
    
   NSString *xmlFileString = [[NSBundle mainBundle] pathForResource:@"license_key_ios" ofType:@"xml"];
  
    [CPDFKit verifyWithPath:xmlFileString completionHandler:^(CPDFKitOnlineLicenseCode code, NSString *message) {
        NSLog(@"Code: %ld, message: %@", (long)code, message);
    }];
}

编译并运行项目。如果控制台输出"version information",则表示许可证设置成功。否则,请查看2.5.6故障排除部分或在控制台中检查错误日志,快速识别和解决问题。