我在Json中获取PDF,检索它并将其显示在webview中,但我还需要它与UIActivityViewController共享,但是当我通过webview时它没有显示可用于共享的选项
我正在做以下事情:
//I get the json
if let url = URL(string: "http://10.1.80.106:9000/api/recibo/imprimir?vigencia=2015-06-30") {
var urlRequest = URLRequest(url: url)
urlRequest.setValue("application/pdf", forHTTPHeaderField: "Content-Type")
urlRequest.setValue("aaaabbbccc", forHTTPHeaderField: "Authorization")
//i create the webview
let webView = UIWebView(frame: self.view.frame)
webView.loadRequest(urlRequest as URLRequest)
webView.scalesPageToFit = true
let pdfVC = UIViewController()
pdfVC.view.addSubview(webView)
pdfVC.title = "Recibo de Pagamento"
self.navigationController?.pushViewController(pdfVC, animated: true)
//instantiate the UIActivityViewController for the share, and step the WebView as parameter
let vc = UIActivityViewController(activityItems: [(webView.request?.url?.absoluteString) as Any], applicationActivities: [])
if let popoverController = vc.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = self.view.bounds
}
self.present(vc, animated: true, completion: nil)
}
答案 0 :(得分:0)
实际上,除了WebView之外,您还可以使用专为此特定目的而设计的QuickLook Framework。你过去了 文件的位置并符合协议。它会呈现 内置文档的视图控制器。您还可以使用本机选项来共享文件。
查看 this 有关其实施和示例的答案。