|
@@ -0,0 +1,103 @@
|
|
|
+import UIKit
|
|
|
+import Foundation
|
|
|
+import ComPDFKit
|
|
|
+import ComPDFKit_Tools
|
|
|
+
|
|
|
+@objc(ComPDFKit)
|
|
|
+class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
|
|
|
+
|
|
|
+
|
|
|
+ @objc(getVersionCode:withRejecter:)
|
|
|
+ func getVersionCode(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
|
+ resolve(String(CPDFKit.sharedInstance().versionNumber))
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @objc(getSDKBuildTag:withRejecter:)
|
|
|
+ func getSDKBuildTag(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
|
+ let sdkBuildTag = CPDFKit.sharedInstance().versionString
|
|
|
+ resolve(sdkBuildTag)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc(init_: withResolver: withRejecter:)
|
|
|
+ func init_(license : String,resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ var code = CPDFKit.verify(withKey: license)
|
|
|
+ print("ComPDFKitRN-iOS init_:\(code)")
|
|
|
+ resolve(code == CPDFKitLicenseCode.success)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc(initialize: iosOnlineLicense: withResolver: withRejecter:)
|
|
|
+ func initialize(_ androidOnlineLicense: String, iosOnlineLicense: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ CPDFKit.verify(withOnlineLicense: iosOnlineLicense) { code, message in
|
|
|
+ print("ComPDFKitRN-iOS initialize: \(code), Message:\(String(describing: message))")
|
|
|
+ resolve(code == CPDFKitOnlineLicenseCode.success)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @objc(openDocument: password: configurationJson:)
|
|
|
+ func openDocument(document : URL, password: String, configurationJson : String) -> Void {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let rootNav = ComPDFKit.presentedViewController()
|
|
|
+
|
|
|
+ let jsonDataParse = CPDFJSONDataParse(String: configurationJson)
|
|
|
+ guard let configuration = jsonDataParse.configuration else { return }
|
|
|
+
|
|
|
+ let pdfViewController = CPDFViewController(filePath: document.path, password: password, configuration: configuration)
|
|
|
+ pdfViewController.delegate = self
|
|
|
+ let nav = CNavigationController(rootViewController: pdfViewController)
|
|
|
+ nav.modalPresentationStyle = .fullScreen
|
|
|
+ rootNav?.present(nav, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ func PDFViewBaseControllerDissmiss(_ baseControllerDelete: CPDFViewBaseController) {
|
|
|
+ baseControllerDelete.dismiss(animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ class func presentedViewController() -> UIViewController? {
|
|
|
+
|
|
|
+ var rootViewController: UIViewController? = nil
|
|
|
+
|
|
|
+ if let appDelegate = UIApplication.shared.delegate as? NSObject {
|
|
|
+ if appDelegate.responds(to: Selector(("viewController"))) {
|
|
|
+ rootViewController = appDelegate.value(forKey: "viewController") as? UIViewController
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if rootViewController == nil, let appDelegate = UIApplication.shared.delegate as? NSObject, appDelegate.responds(to: #selector(getter: UIApplicationDelegate.window)) {
|
|
|
+ if let window = appDelegate.value(forKey: "window") as? UIWindow {
|
|
|
+ rootViewController = window.rootViewController
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if rootViewController == nil {
|
|
|
+ if let window = UIApplication.shared.keyWindow {
|
|
|
+ rootViewController = window.rootViewController
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ guard let finalRootViewController = rootViewController else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ var currentViewController = finalRootViewController
|
|
|
+
|
|
|
+ while let presentedViewController = currentViewController.presentedViewController {
|
|
|
+ if !(presentedViewController is UIAlertController) && currentViewController.modalPresentationStyle != .popover {
|
|
|
+ currentViewController = presentedViewController
|
|
|
+ } else {
|
|
|
+ return currentViewController
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return currentViewController
|
|
|
+ }
|
|
|
+
|
|
|
+}
|