FileExplorer icon indicating copy to clipboard operation
FileExplorer copied to clipboard

Using custom FileSpecificationProvider

Open ottz972 opened this issue 7 years ago • 0 comments

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)
    }
}

ottz972 avatar Jun 16 '17 19:06 ottz972