diff --git a/example/ZXFileBrowserDemo.xcodeproj/project.pbxproj b/example/ZXFileBrowserDemo.xcodeproj/project.pbxproj index 9740a7a..2718e53 100644 --- a/example/ZXFileBrowserDemo.xcodeproj/project.pbxproj +++ b/example/ZXFileBrowserDemo.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ E47EB8EC264D11EB00C17260 /* zxfilebrowser.png in Resources */ = {isa = PBXBuildFile; fileRef = E47EB8EB264D11EB00C17260 /* zxfilebrowser.png */; }; E47EB8EF264D131D00C17260 /* folder.png in Resources */ = {isa = PBXBuildFile; fileRef = E47EB8ED264D131D00C17260 /* folder.png */; }; E47EB8F0264D131D00C17260 /* file.png in Resources */ = {isa = PBXBuildFile; fileRef = E47EB8EE264D131D00C17260 /* file.png */; }; + E4EC33EC2657BF5C00074E19 /* 1470296169586813.jpg in Resources */ = {isa = PBXBuildFile; fileRef = E4EC33EB2657BF5B00074E19 /* 1470296169586813.jpg */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -45,6 +46,7 @@ E47EB8EB264D11EB00C17260 /* zxfilebrowser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = zxfilebrowser.png; sourceTree = ""; }; E47EB8ED264D131D00C17260 /* folder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = folder.png; sourceTree = ""; }; E47EB8EE264D131D00C17260 /* file.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = file.png; sourceTree = ""; }; + E4EC33EB2657BF5B00074E19 /* 1470296169586813.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 1470296169586813.jpg; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -108,6 +110,7 @@ E47EB8D5264A944500C17260 /* pod */, E47EB8C1264A92ED00C17260 /* AppDelegate.swift */, E47EB8C5264A92ED00C17260 /* ViewController.swift */, + E4EC33EB2657BF5B00074E19 /* 1470296169586813.jpg */, E47EB8C7264A92ED00C17260 /* Main.storyboard */, E47EB8CA264A92EE00C17260 /* Assets.xcassets */, E47EB8CC264A92EE00C17260 /* LaunchScreen.storyboard */, @@ -240,6 +243,7 @@ E47EB8C9264A92ED00C17260 /* Main.storyboard in Resources */, E47EB8EF264D131D00C17260 /* folder.png in Resources */, E47EB8F0264D131D00C17260 /* file.png in Resources */, + E4EC33EC2657BF5C00074E19 /* 1470296169586813.jpg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/example/ZXFileBrowserDemo.xcworkspace/xcuserdata/damon.xcuserdatad/UserInterfaceState.xcuserstate b/example/ZXFileBrowserDemo.xcworkspace/xcuserdata/damon.xcuserdatad/UserInterfaceState.xcuserstate index f3df33e..1040c89 100644 Binary files a/example/ZXFileBrowserDemo.xcworkspace/xcuserdata/damon.xcuserdatad/UserInterfaceState.xcuserstate and b/example/ZXFileBrowserDemo.xcworkspace/xcuserdata/damon.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/example/ZXFileBrowserDemo.xcworkspace/xcuserdata/damon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/example/ZXFileBrowserDemo.xcworkspace/xcuserdata/damon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..b20a4ee --- /dev/null +++ b/example/ZXFileBrowserDemo.xcworkspace/xcuserdata/damon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git a/example/ZXFileBrowserDemo/1470296169586813.jpg b/example/ZXFileBrowserDemo/1470296169586813.jpg new file mode 100755 index 0000000..8deeb49 Binary files /dev/null and b/example/ZXFileBrowserDemo/1470296169586813.jpg differ diff --git a/example/ZXFileBrowserDemo/ViewController.swift b/example/ZXFileBrowserDemo/ViewController.swift index bbf6085..9e56c03 100644 --- a/example/ZXFileBrowserDemo/ViewController.swift +++ b/example/ZXFileBrowserDemo/ViewController.swift @@ -7,6 +7,7 @@ import UIKit import ZXKitCore +import ZXKitUtil class ViewController: UIViewController { @@ -15,6 +16,9 @@ class ViewController: UIViewController { // Do any additional setup after loading the view. self.createUI() ZXKit.regist(plugin: ZXFileBrowser.shared) + + + } @@ -28,6 +32,16 @@ class ViewController: UIViewController { @objc func _click() { ZXKit.show() + + + let path = Bundle.main.path(forResource: "1470296169586813", ofType: "jpg") + if let path = path, let data = try? Data(contentsOf: URL(fileURLWithPath: path)) { + do { + try data.write(to: ZXKitUtil.shared.getFileDirectory(type: .caches).appendingPathComponent("3333.jpg")) + } catch { + print(error) + } + } } } diff --git a/pod/ZXFileBrowser.swift b/pod/ZXFileBrowser.swift index 5ba40e3..34e5f6a 100644 --- a/pod/ZXFileBrowser.swift +++ b/pod/ZXFileBrowser.swift @@ -10,6 +10,11 @@ import ZXKitUtil #if canImport(ZXKitCore) import ZXKitCore #endif +import MobileCoreServices + +enum ZXFileType { + case unknown +} open class ZXFileBrowser: NSObject { private static let instance = ZXFileBrowser() @@ -37,5 +42,22 @@ open class ZXFileBrowser: NSObject { } extension ZXFileBrowser { - + func getFileType(filePath: URL?) -> CFString? { + guard let filePath = filePath else { return nil } + let fileExt = filePath.pathExtension + // 把文件转换成 Uniform Type Identifiers 后获取文件的 tag + let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExt as CFString, nil) + if let retainedValue = uti?.takeRetainedValue() { + // 通过UTTypeConformsTo 方法来判断文件类型是否为图片,kUTTypeImage 是需要比较的文件类型 +// if UTTypeConformsTo((uti?.takeRetainedValue())!, kUTTypeImage){ +// print("这是一个图片") +// // 接下来的操作 +// } + print(retainedValue) + return retainedValue + } else { + return nil + } + + } } diff --git a/pod/vc/ZXFileBrowserVC.swift b/pod/vc/ZXFileBrowserVC.swift index c50890b..3546754 100644 --- a/pod/vc/ZXFileBrowserVC.swift +++ b/pod/vc/ZXFileBrowserVC.swift @@ -7,6 +7,7 @@ import UIKit import ZXKitUtil +import MobileCoreServices func UIImageHDBoundle(named: String?) -> UIImage? { guard let name = named else { return nil } @@ -226,11 +227,17 @@ extension ZXFileBrowserVC: UITableViewDelegate, UITableViewDataSource { if model.isDirectory { mSelectedDirectoryPath = mSelectedDirectoryPath + "/" + model.name self._loadData() + if let type = ZXFileBrowser.shared.getFileType(filePath: ZXKitUtil.shared.getFileDirectory(type: .documents)) { + print(type, UTTypeConformsTo(type, kUTTypeDirectory)) + } + } else { let rightBarItem = UIBarButtonItem(title: NSLocalizedString("close", comment: ""), style: .plain, target: self, action: #selector(_rightBarItemClick)) self.navigationItem.rightBarButtonItem = rightBarItem self.mSelectedFilePath = self.currentDirectoryPath.appendingPathComponent(model.name, isDirectory: false) self._showMore() + + ZXFileBrowser.shared.getFileType(filePath: self.mSelectedFilePath) } } }