This repository was archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathFileReaderView.swift
More file actions
76 lines (45 loc) · 1.78 KB
/
FileReaderView.swift
File metadata and controls
76 lines (45 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// FileReaderView.swift
// flutter_filereader
//
// Created by 胡杰 on 2019/3/6.
//
import UIKit
import WebKit
class FileReaderView: NSObject,FlutterPlatformView {
var _webView: FileReaderWKWebView?
init(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?,binaryMessenger messenger: FlutterBinaryMessenger) {
super.init()
let channel = FlutterMethodChannel.init(name: "wv.io/FileReader_\(viewId)", binaryMessenger: messenger)
channel.setMethodCallHandler { (call, result) in
if call.method == "openFile" {
if isSupportOpen(fileType: fileType(filePath: call.arguments as? String)){
self.openFile(filePath: call.arguments as! String)
result(true)
}else{
result(false)
}
return
}
if call.method == "canOpen" {
result(isSupportOpen(fileType: fileType(filePath: call.arguments as? String)))
return
}
}
self._webView = FileReaderWKWebView.init(frame: frame)
// 隐藏垂直线条
_webView?.scrollView.showsVerticalScrollIndicator = false
}
func openFile(filePath:String) {
let url = URL.init(fileURLWithPath: filePath)
if #available(iOS 9.0, *) {
_webView?.loadFileURL(url, allowingReadAccessTo: url)
} else {
let request = URLRequest.init(url: url)
_webView?.load(request)
}
}
func view() -> UIView {
return _webView!
}
}