【发布时间】:2019-12-12 10:57:32
【问题描述】:
我想从应用程序共享 pdf 文件。我收到一个错误“无法共享”文档一些 pdf。我在某些文件中没有收到错误。这是我的代码:
class DocumentURL: UIActivityItemProvider {
let temporaryURL: URL
let document: DocumentAndDemandForm
let data : Data
init(document: DocumentAndDemandForm,data:Data) {
self.document = document
self.data = data
self.temporaryURL = URL(fileURLWithPath: NSTemporaryDirectory() + "\(document.downloadName == "" ? document.description ?? "ek" : document.downloadName).pdf")
super.init(placeholderItem: temporaryURL)
}
override var item: Any {
get {
try? data.write(to: temporaryURL)
return temporaryURL
}
}
}
func share(isSave:Bool = false) {
if let data = pdfView.document?.dataRepresentation(){
let activityViewController: UIActivityViewController = UIActivityViewController(activityItems: [DocumentURL.init(document: self.document, data: data)], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.pdfView
if isSave{
activityViewController.excludedActivityTypes = [.airDrop,.assignToContact,.copyToPasteboard,.mail,.message,.openInIBooks,.postToFacebook,.postToFlickr,.postToTencentWeibo,.postToTwitter,.postToVimeo,.postToWeibo]
}
DispatchQueue.main.async {
self.controller.present(activityViewController, animated: true, completion: {
self.shareDocument = false
})
}
}
}
【问题讨论】:
标签: swift pdf document whatsapp uiactivityviewcontroller