Hi
I'm trying to share a PDF file stored on the phone using the UIDocumentInteractionController
But even though the menu appears with all the options none of them work. I think I was able to provide a bit of more information when I tried to use the AirDrop. I got a debug message saying "The transferer faild because there are no valid files to send" (this is a rough translation, the message was localized)
I have the following code
extension ExportedReportsTableViewController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
func shareFile(filePath: String, loc: CGRect) {
let stripPath = filePath.components(separatedBy: "/")
let fileName = stripPath[stripPath.count - 1]
let timestamp = fileName.replacingOccurrences(of: "Report", with: "").replacingOccurrences(of: ".pdf", with: "")
let newFileName = Date(ticks: Double(timestamp)!).toString(format: "dd MMMM yyyy HH:mm")
let nsURL = NSURL.fileURL(withPath: filePath)
let url = nsURL as URL
let dic = UIDocumentInteractionController(url: url.absoluteURL)
dic.uti = "com.adobe.pdf"
dic.delegate = self
dic.name = newFileName
//dic.presentPreview(animated: true) <-- It works perfectly
dic.presentOptionsMenu(from: loc, in: self.view, animated: true)
}
}
If I use the (presentPreview) method it works perfectly (even the share inside that controller) but with the presentOptionsMenu method it fails to send (the menu appears)
I can only assume that's a function for the delegate? The url is valid (it works on the preview)
Any ideas?
BTW it's possible, when sending change the file name?
For example the file name is "Report082182414.pdf" and when sent it appears "17 July 2017.pdf" (I know a work arround but requires copying the file with a new name and I wanted to avoid that)
Thanks in advance
Pedro Cavaleiro