2017-02-22 111 views
0

我在模擬器上任何有像Adobe沒有應用程序打開PDF文件的工作....我使用UIDocumentInteractionController打開PDF文件,如下圖所示。PDF文件無法打開UIDocumentInteractionController

let url=URL(fileURLWithPath: "/Users/sai/Library/Developer/CoreSimulator/Devices/425D8615-ADEC-4334-A639-C30B1E675EFA/data/Containers/Data/Application/AB3787BF-F6AC-4111-9847-A0FDC4E899F8/tmp/samplepdf.pdf") 

    print("--------------------------------- str is \(url)") 
    if (url != nil) { 
     // Initialize Document Interaction Controller 
     self.documentInteractionController = UIDocumentInteractionController(url: url) 
     // Configure Document Interaction Controller 
     self.documentInteractionController?.delegate = self 
     // Preview PDF 
     self.documentInteractionController?.presentOptionsMenu(from: self.view.frame, in: self.view, animated: true) 
    } 


    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController { 
      return self 
    } 

我的屏幕是越來越顯示像下面 No pdf is being displayed here...is it because there is no app in my simulator which could open pdf files?

回答

0

不知道任何模擬器的應用程序將處理PDF文檔 - 也許新聞?但您可以將一個webView添加到視圖控制器並使用它來查看您的PDF。

@IBOutlet weak var webView: UIWebView! 

請在您的網址,然後通常的安全檢查:

webView.loadRequest(NSURLRequest(url: url as URL) as URLRequest) 
0

我覺得這是一個路徑問題。

更換

let url=URL(fileURLWithPath: "/Users/sai/Library/Developer/CoreSimulator/Devices/425D8615-ADEC-4334-A639-C30B1E675EFA/data/Containers/Data/Application/AB3787BF-F6AC-4111-9847-A0FDC4E899F8/tmp/samplepdf.pdf") 

隨着

let url = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("samplepdf.pdf") 

爲雨燕3/Xcode中8

let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("samplepdf.pdf") as NSURL 

希望這將有助於。