2017-02-22 108 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 

希望这将有助于。