在iOS 8中打开PDF URL? [英] open PDF URL in iOS 8?

查看:363
本文介绍了在iOS 8中打开PDF URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已编写此代码以使用UIDocumentInteractionController显示pdf.But,我不知道如何在本地目录中搜索pdf并在iOS 8及以下版本中打开..有什么帮助吗?

I have write this code to show pdf using UIDocumentInteractionController.But,I don't know how to search pdf at local directory and open in iOS 8 and below..Any help?

let filename = history.invoiceLongDate // 01223642
            if !filename.isEmpty{
                let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
                let docs = paths[0]
                let pathURL = NSURL(fileURLWithPath: docs, isDirectory: true)
                if #available(iOS 9.0, *) {
                    let fileURL = NSURL(fileURLWithPath: "\(filename)_my_invoice.pdf", isDirectory: false, relativeToURL: pathURL)
                    self.docController = UIDocumentInteractionController(URL: fileURL)
                    self.docController?.delegate = self
                    self.docController?.presentOptionsMenuFromRect(sender.frame, inView: self.view, animated: true)
                } else {
                    // Fallback on earlier versions
                    // Any Help with that?
                }
            }


推荐答案

UIDocumentInteractionController可用于(iOS 3.2,*)。

UIDocumentInteractionController is available with (iOS 3.2, *).

用于查看PDF文件:

var documentInteractionController: UIDocumentInteractionController!

@IBAction func openDocument(sender: UIButton) {
  let URL: NSURL = NSBundle.mainBundle().URLForResource("pdf-sample", withExtension: "pdf")!

    if (URL != "") {
        // Initialize Document Interaction Controller
        self.documentInteractionController = UIDocumentInteractionController(URL: URL)

        // Configure Document Interaction Controller
        self.documentInteractionController.delegate = self

        // Present Open In Menu
        self.documentInteractionController.presentOptionsMenuFromRect(sender.frame, inView: self.view, animated: true)
            //presentOpenInMenuFromRect(button.frame, inView: self.view, animated: true)
    }
}

// MARK: UIDocumentInteractionControllerDelegate
func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) -> UIViewController {
    return self
}

这篇关于在iOS 8中打开PDF URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆