فهرست منبع

compdfkit(rn) - ios 端对接

liuxiaolong 10 ماه پیش
والد
کامیت
05e12dc4f3

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 67 - 41
example/App.tsx


+ 4 - 0
example/ios/CompdfkitPdfExample.xcodeproj/project.pbxproj

@@ -14,6 +14,7 @@
 		13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
 		7699B88040F8A987B510C191 /* libPods-CompdfkitPdfExample-CompdfkitPdfExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-CompdfkitPdfExample-CompdfkitPdfExampleTests.a */; };
 		81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
+		EC6D60D22BDE4982003FB442 /* PDF_Document.pdf in Resources */ = {isa = PBXBuildFile; fileRef = EC6D60D12BDE4982003FB442 /* PDF_Document.pdf */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -43,6 +44,7 @@
 		5DCACB8F33CDC322A6C60F78 /* libPods-CompdfkitPdfExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CompdfkitPdfExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
 		81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = CompdfkitPdfExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
 		89C6BE57DB24E9ADA2F236DE /* Pods-CompdfkitPdfExample-CompdfkitPdfExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CompdfkitPdfExample-CompdfkitPdfExampleTests.release.xcconfig"; path = "Target Support Files/Pods-CompdfkitPdfExample-CompdfkitPdfExampleTests/Pods-CompdfkitPdfExample-CompdfkitPdfExampleTests.release.xcconfig"; sourceTree = "<group>"; };
+		EC6D60D12BDE4982003FB442 /* PDF_Document.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = PDF_Document.pdf; sourceTree = "<group>"; };
 		ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
 /* End PBXFileReference section */
 
@@ -116,6 +118,7 @@
 		83CBB9F61A601CBA00E9B192 = {
 			isa = PBXGroup;
 			children = (
+				EC6D60D12BDE4982003FB442 /* PDF_Document.pdf */,
 				13B07FAE1A68108700A75B9A /* CompdfkitPdfExample */,
 				832341AE1AAA6A7D00B99B32 /* Libraries */,
 				00E356EF1AD99517003FC87E /* CompdfkitPdfExampleTests */,
@@ -244,6 +247,7 @@
 			files = (
 				81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
 				13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
+				EC6D60D22BDE4982003FB442 /* PDF_Document.pdf in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 1 - 1
example/ios/CompdfkitPdfExample/Info.plist

@@ -27,7 +27,7 @@
 	<key>NSAppTransportSecurity</key>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>
-		<false/>
+		<true/>
 		<key>NSAllowsLocalNetworking</key>
 		<true/>
 	</dict>

BIN
example/ios/PDF_Document.pdf


+ 1 - 1
example/package.json

@@ -12,7 +12,7 @@
   },
   "dependencies": {
     "react": "18.2.0",
-    "react-native": "0.73.3",
+    "react-native": "0.73.4",
     "react-native-document-picker": "^9.1.0"
   },
   "devDependencies": {

+ 18 - 6
ios/ComPDFKit.mm

@@ -2,15 +2,27 @@
 
 @interface RCT_EXTERN_MODULE(ComPDFKit, NSObject)
 
-RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
-                 withResolver:(RCTPromiseResolveBlock)resolve
-                 withRejecter:(RCTPromiseRejectBlock)reject)
 
-RCT_EXTERN_METHOD(getSDKBuildTag:
-                 withResolver:(RCTPromiseResolveBlock)resolve
-                 withRejecter:(RCTPromiseRejectBlock)reject)
+RCT_EXTERN_METHOD(getVersionCode:(RCTPromiseResolveBlock)resolve
+                  withRejecter:(RCTPromiseRejectBlock)reject)
 
 
+RCT_EXTERN_METHOD(getSDKBuildTag:(RCTPromiseResolveBlock)resolve
+                  withRejecter:(RCTPromiseRejectBlock)reject)
+
+RCT_EXTERN_METHOD(init_:(NSString *)license
+                  withResolver:(RCTPromiseResolveBlock)resolve
+                  withRejecter:(RCTPromiseRejectBlock)reject)
+
+RCT_EXTERN_METHOD(initialize:(NSString *)androidOnlineLicense
+                  iosOnlineLicense:(NSString *)iosOnlineLicense
+                  withResolver:(RCTPromiseResolveBlock)resolve
+                  withRejecter:(RCTPromiseRejectBlock)reject)
+
+RCT_EXTERN_METHOD(openDocument:(NSURL *)document
+                  password:(NSString *)password
+                  configurationJson:(NSString *)configurationJson)
+
 + (BOOL)requiresMainQueueSetup
 {
   return NO;

+ 0 - 20
ios/ComPDFKit.swift

@@ -1,20 +0,0 @@
-import ComPDFKit
-import ComPDFKit_Tools
-
-@objc(ComPDFKit)
-class ComPDFKit: NSObject {
-
-  @objc(multiply:withB:withResolver:withRejecter:)
-  func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
-    resolve(a*b)
-  }
-    
-
-    @objc(getSDKBuildTag:withResolver:withRejecter:)
-      func getSDKBuildTag(_ dummy: Any, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
-        // Implement your getSDKBuildTag logic here
-        // For example:
-        let sdkBuildTag = "ios test sdkBuildTag"
-        resolve(sdkBuildTag)
-      }
-}

+ 103 - 0
ios/ComPDFKitRN.swift

@@ -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
+    }
+    
+}