Augustyniak / FileExplorer

FileExplorer is a powerful iOS file browser that allows its users to choose and remove files and/or directories
Other
742 stars 112 forks source link

Using custom FileSpecificationProvider #32

Open ottz972 opened 7 years ago

ottz972 commented 7 years ago

I'm attempting to utilize a custom FileSpecificationProvider to display .txt files in a certain format, however the FileExplorerViewController brings up the UknownFileTypeViewController instead.

class FileViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let fileExplorer = FileExplorerViewController()
        fileExplorer.delegate = self as? FileExplorerViewControllerDelegate
        fileExplorer.fileSpecificationProviders = [TXTSpecificationProvider.self]

        self.present(fileExplorer, animated: true, completion: nil)
    }
}

public class TXTSpecificationProvider: FileSpecificationProvider {
    public class var extensions: [String] {
        return ["txt"]
    }

    public static func thumbnail(forItemAt url: URL, with size: CGSize) -> UIImage? {
        return nil
    }

    public class func viewControllerForItem(at url: URL, data: Data?, attributes: FileAttributes) -> UIViewController {
        return ThisPlacePreviewViewController(fileName: url.absoluteString)
    }
}