Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonHu committed May 21, 2021
1 parent 63d3214 commit a0a10ec
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions example/ZXFileBrowserDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -45,6 +46,7 @@
E47EB8EB264D11EB00C17260 /* zxfilebrowser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = zxfilebrowser.png; sourceTree = "<group>"; };
E47EB8ED264D131D00C17260 /* folder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = folder.png; sourceTree = "<group>"; };
E47EB8EE264D131D00C17260 /* file.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = file.png; sourceTree = "<group>"; };
E4EC33EB2657BF5B00074E19 /* 1470296169586813.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 1470296169586813.jpg; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -108,6 +110,7 @@
E47EB8D5264A944500C17260 /* pod */,
E47EB8C1264A92ED00C17260 /* AppDelegate.swift */,
E47EB8C5264A92ED00C17260 /* ViewController.swift */,
E4EC33EB2657BF5B00074E19 /* 1470296169586813.jpg */,
E47EB8C7264A92ED00C17260 /* Main.storyboard */,
E47EB8CA264A92EE00C17260 /* Assets.xcassets */,
E47EB8CC264A92EE00C17260 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -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;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "72E949D4-B328-4674-A35D-EB10A293768C"
type = "0"
version = "2.0">
</Bucket>
Binary file added example/ZXFileBrowserDemo/1470296169586813.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions example/ZXFileBrowserDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import ZXKitCore
import ZXKitUtil

class ViewController: UIViewController {

Expand All @@ -15,6 +16,9 @@ class ViewController: UIViewController {
// Do any additional setup after loading the view.
self.createUI()
ZXKit.regist(plugin: ZXFileBrowser.shared)




}

Expand All @@ -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)
}
}
}

}
Expand Down
24 changes: 23 additions & 1 deletion pod/ZXFileBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

}
}
7 changes: 7 additions & 0 deletions pod/vc/ZXFileBrowserVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import ZXKitUtil
import MobileCoreServices

func UIImageHDBoundle(named: String?) -> UIImage? {
guard let name = named else { return nil }
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit a0a10ec

Please sign in to comment.