Having issues with my UIDocumentInteractionController
. I am trying to handle unsupported file types by transferring to apps that support them. Below is my relevant code.
class AttachmentsView: UICollectionView, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIDocumentInteractionControllerDelegate {
var docController: UIDocumentInteractionController!
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
switch filetype {
case: .image:
return
case: .document:
return
case: .audio:
return
case: .video:
return
case .unknown:
let unknownFile = files[(indexPath as NSIndexPath).item]
guard let fileURL = unknownFile.fullPath else {
return
}
self.docController = UIDocumentInteractionController(url: fileURL)
self.docController.delegate = self
self.docController.url = fileURL
self.docController.presentOpenInMenu(from: (superview?.frame)!, in: self, animated: true)
return
}
}
Here is what my fileURL
looks like -
file:///private/var/mobile/Containers/Data/Application/1E67D26D-B9FE-4455-8D30-6A4FED07071E/tmp/folder_attachments/a9500123-c5e6-469b-8867-af72050f453e/1b177057-c507-445a-a8a0-b7b349ae79c6.zip
In this example it's a .zip file. The UIDocumentInteractionController
comes up just fine as an activity sheet type view. Shows AirDrop, Add to Notes, Add to Health, Import with Dropbox and a few more. I can also add to iCloud drive.
When I tap on the Dropbox option, It goes through:
func documentInteractionController(_ controller: UIDocumentInteractionController, willBeginSendingToApplication application: String?) {
print("begin sending")
}
But does not go through:
func documentInteractionController(_ controller: UIDocumentInteractionController, didEndSendingToApplication application: String?) {
print("completed")
}
Another hint is when I tap AirDrop I get Error = "Error Domain=SFOperation Code=-5 \"The transfer failed because you tried to send an invalid file.\"
Any idea why this might be happening? Thank you.