@@ -12,7 +12,7 @@ public class CompdfkitFlutterPlugin: NSObject, FlutterPlugin, CPDFViewBaseContro
12
12
let factory = CPDFViewCtrlFactory ( messenger: registrar. messenger ( ) )
13
13
registrar. register ( factory, withId: " com.compdfkit.flutter.ui.pdfviewer " )
14
14
}
15
-
15
+
16
16
public func handle( _ call: FlutterMethodCall , result: @escaping FlutterResult ) {
17
17
switch call. method {
18
18
case " sdk_version_code " :
@@ -35,17 +35,29 @@ public class CompdfkitFlutterPlugin: NSObject, FlutterPlugin, CPDFViewBaseContro
35
35
let jsonString = initInfo ? [ " configuration " ] ?? " "
36
36
_ = initInfo ? [ " password " ] ?? " "
37
37
let path = initInfo ? [ " document " ] as? String ?? " "
38
+ let document = NSURL ( fileURLWithPath: path)
39
+
40
+ let fileManager = FileManager . default
41
+ let samplesFilePath = NSHomeDirectory ( ) . appending ( " /Documents/Files " )
42
+ let fileName = document. lastPathComponent ?? " "
43
+ let docsFilePath = samplesFilePath + " / " + fileName
44
+
45
+ if !fileManager. fileExists ( atPath: samplesFilePath) {
46
+ try ? FileManager . default. createDirectory ( atPath: samplesFilePath, withIntermediateDirectories: true , attributes: nil )
47
+ }
48
+
49
+ try ? FileManager . default. copyItem ( atPath: document. path ?? " " , toPath: docsFilePath)
38
50
39
51
let jsonDataParse = CPDFJSONDataParse ( String: jsonString as! String )
40
52
guard let configuration = jsonDataParse. configuration else { return }
41
53
if let rootViewControl = UIApplication . shared. keyWindow? . rootViewController {
42
54
var tRootViewControl = rootViewControl
43
-
55
+
44
56
if let presentedViewController = rootViewControl. presentedViewController {
45
57
tRootViewControl = presentedViewController
46
58
}
47
-
48
- let pdfViewController = CPDFViewController ( filePath: path , password: nil , configuration: configuration)
59
+
60
+ let pdfViewController = CPDFViewController ( filePath: docsFilePath , password: nil , configuration: configuration)
49
61
let navController = CNavigationController ( rootViewController: pdfViewController)
50
62
pdfViewController. delegate = self
51
63
navController. modalPresentationStyle = . fullScreen
0 commit comments