iOS開源 - 一款完整的文件資源管理器組件

foxmyth 8年前發布 | 11K 次閱讀 iOS開發 移動開發

FileExplorer (iOS 10.0+)

:construction_worker: Project created and maintained by Rafa? Augustyniak . 

Introduction

FileExplorer is a control designed to provide an easy way to browse and interact with local file system on iOS devices. It works as file browser with additional possibility of deleting specified files and/or directories and possibility to choose files and/or directories.

  Main Features
:point_right: Possibility to choose files or/and directories if there is a need for that
?? Possiblity to remove files or/and directories if there is a need for that
:mag: Built-in search functionality
:books: Documented
:house: Out of the box support for image, audio, video and pdf files
:rocket: Extendable API; Possibility to add support for any file type
:bird: Written in Swift
Images Audio Files Videos Directories PDFs Preview

Table of Contents:

  • Installation
  • Basic Usage
  • Customizations
    • Deciding Which Files and/or Directories Should Be Visible
    • Using FileExplorer as a Way to Choose Files and/or Directories
    • Deciding Whether User Can Delete Files and/or Directories
    </li>
  • Adding Support for Additional File Types
  • Documentation
  • </ul>

    Installation

    CocoaPods

    CocoaPods is the recommended way to add FileExplorer to your project.

    1. Add additional entry to your Podfile.

      pod "FileExplorer", "~> 1.0.2"
    2. Install Pod(s) running pod install command.

    3. Include FileExplorer using import FileExplorer .

    Source files

    1. Downloaded the latest version of the library usinglink.
    2. Copy content of the downloaded (and unzipped) zip file into your project by dragging it into Project's navigator files structure.

    Basic Usage

    Check out the demo for example usage of library. Make sure you read the FileExplorer documentation on Cocoa Docs .

    Basics

    1. Add following import in file of your project when you want to use RATreeView:

      import FileExplorer
    2. Simplest way to present File Explorer:

      let fileExplorer = FileExplorerViewController()
      self.present(fileExplorer, animated: true, completion: nil)

    Customizations

    FileExplorer allows for a lot of customizations. Some of them are discussed below.

    Deciding Which Files and/or Directories Should Be Visible

    FileExplorerViewController has filters ( fileFilters and ignoredFileFilters properties) which can be used to select which files or directories should or shouldn't be displayed to the user.

    Specify which files should be visible to the user:

    let fileExplorer = FileExplorerViewController()

    //Only files with txt and jpg extensions will be visible fileExplorer.fileFilters = [Filter.extension("txt"), Filter.extension("jpg")]

    self.present(fileExplorer, animated: true, completion: nil)</code></pre>

    Specify which files should not be visible to the user:

    let fileExplorer = FileExplorerViewController()

    //Everything but directories will be visible fileExplorer.ignoredFileFilters = [Filter.type(.directory)]

    self.present(fileExplorer, animated: true, completion: nil)</code></pre>

    Combining both types of filters:

    let fileExplorer = FileExplorerViewController()

    //Only files with .txt extension that were modified prior to referenceDate will be visible fileExplorer.fileFilters = [Filter.extension("txt")] fileExplorer.ignoredFileFilters = [Filter.Filter.modificationDatePastOrEqualTo(referenceDate)]

    self.present(fileExplorer, animated: true, completion: nil)</code></pre>

    Using FileExplorer as a Way to Choose Files and/or Directories

    Configure FileExplorer so that user is allowed to choose files and/or directories:

    let fileExplorer = FileExplorerViewController()
    fileExplorer.canChooseFiles = true //specify whether user is allowed to choose files
    fileExplorer.canChooseDirectories = false //specify whether user is allowed to choose directories
    fileExplorer.allowsMultipleSelection = true //specify whether user is allowed to choose multiple files and/or directories
    fileExplorer.delegate = self

    self.present(fileExplorer, animated: true, completion: nil)</code></pre>

    You are informed about choosen files by delegate callback:

    public func fileExplorerViewController(_ controller: FileExplorerViewController, didChooseURLs urls: [URL]) {
        //Your code here
    }

    Deciding Whether User Can Delete Files and/or Directories

    Configure FileExplorer so that user is allowed to remove files and/or directories:

    let fileExplorer = FileExplorerViewController()
    fileExplorer.canRemoveFiles = true //specify whether user is allowed to remove files
    fileExplorer.canRemoveDirectories = false //specify whether user is allowed to remove directories

    self.present(fileExplorer, animated: true, completion: nil)</code></pre>

    Adding Support for Additional File Types

    FileExplorer was built with expansibility in mind. It allows its users to register their own file types and provide thumbnails and preview view controllers for them. The whole process is simple and straightforward.

    It starts with the implementation of class that conforms to FileSpecificationProvider protocol.

    class CustomFileSpecificationProvider: FileSpecificationProvider {
       public class var extensions: [String] {
          return ["foo"]
       }

    public class func thumbnail(forItemAt url: URL, with size: CGSize) -> UIImage? { return nil; // FileExplorer uses default thumbnail if nil is returned }

    public class func viewControllerForItem(at url: URL, data: Data?, attributes: FileAttributes) -> UIViewController { let viewController = CustomViewController() //configure your custom view controller here return viewController } }</code></pre>

    After that, created class must be registered in an instance of FileExplorerViewController class:

    let fileExplorer = FileExplorerViewController()
    fileExplorer.fileSpecificationProviders = [CustomFileSpecificationProvider.self]

    self.present(fileExplorer, animated: true, completion: nil)</code></pre>

    That's all! From now on instance of FileExplorerViewController uses CustomFileSpecificationProvider to provide thumbnails and view controllers for files with foo extension.

    Documentation

    Documentation is available on CocoaPods .

     

     

     

 本文由用戶 foxmyth 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!