2017-09-27 6 views

答えて

0

これはできません。ドキュメンテーションはこれについてよく説明することができますが、独自のビューアを作ろうと思っています。がんばろう!

参照:

Oficial topic IOS

あなたはサイトショーとして行うことができます:あなたは、文書の相互作用のコントローラを持っていたら、あなたは缶」

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL) fileURL 
usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate { 

UIDocumentInteractionController *interactionController = 
    [UIDocumentInteractionController interactionControllerWithURL: fileURL]; 
interactionController.delegate = interactionDelegate; 

return interactionController;} 
を「文書インタラクションコントローラの作成と設定します」そのプロパティを使用して、名前、タイプ、およびURLを含む関連ファイルに関する情報を取得してください。

+0

もちろんできます。それはかなり簡単です。 – orkoden

+0

はい、独自のスクリプトを作成します。リソースが明示的に言語を追加することなく –

+0

上記の私の答えを参照してください。https://stackoverflow.com/a/46451323/1329214 – orkoden

0
  1. 何らかの進行スピナーを表示します。
  2. URLSessionURLSessionDownloadTaskを使用して、~/documentsフォルダにファイルをダウンロードします。
  3. 進行スピナーを非表示にします。
  4. 次に、QLPreviewControllerDataSourceを実装し、ドキュメントを保持するクラスのインスタンスを作成する必要があります。もちろん
  5. 隠す進捗スピナーと存在QLPreviewController

    import UIKit 
    import QuickLook 
    
    
    class Document: NSObject, QLPreviewItem { 
        var previewItemURL: URL? 
    } 
    
    class PreviewDataSource: NSObject, QLPreviewControllerDataSource { 
    
        var document: Document? 
    
        func numberOfPreviewItems(in controller: QLPreviewController) -> Int { 
         return document != nil ? 1 : 0 
        } 
    
        func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { 
         return document! 
        } 
    } 
    
    class ProgressLoadingViewController: UIViewController { 
    
        var session: URLSession = URLSession(configuration: URLSessionConfiguration.default) 
        var downloadTask: URLSessionDownloadTask? 
    
        var dataSource: PreviewDataSource? 
    
        override func viewDidLoad() { 
         super.viewDidLoad() 
         startDownload() 
        } 
    
        func startDownload() { 
         // start progres spinner 
         downloadTask = session.downloadTask(with: URL(string: "http://che.org.il/wp-content/uploads/2016/12/pdf-sample.pdf")!) { [weak self] (downloadLocation, response, error) in 
          guard // check if download went correctly 
           error != nil, 
           let filename = response?.suggestedFilename, 
           let downloadLocation = downloadLocation 
           else { 
            print("Something went wrong: \(error!)") 
            return 
          } 
    
          // copy file 
          let fileManager = FileManager.default 
          let targetPath = URL(fileURLWithPath: filename, relativeTo: fileManager.temporaryDirectory) 
          do { 
           try fileManager.copyItem(at: downloadLocation, to: targetPath) 
          } catch let fileError { 
           print("Copying failed: \(fileError)") 
           return 
          } 
    
          // prepare preview 
          let document = Document() 
          document.previewItemURL = targetPath 
          self?.dataSource? = PreviewDataSource() 
          self?.dataSource?.document = document 
    
          let qlViewController = QLPreviewController() 
          qlViewController.dataSource = self?.dataSource 
    
          // hide progress spinner 
          self?.present(qlViewController, animated: true) { 
           self?.downloadTask = nil 
           qlViewController.reloadData() 
          } 
         } 
         downloadTask?.resume() 
        } 
    } 
    

この長い補完機能がいくつかに分割して、独自のクラスDocumentDownloadManagerに移動する必要があります。

+0

私は客観的なCの私に答えることができますか? @orkoden – monali

関連する問題