I tried the share method with the URL link in my bundle and the PDF can also be shared. But as soon as I try to share my saved (core data with reference to documentDirectory where the PDF's are located) the error [ShareSheet] connection invalidated.
Is it because the PDFs are saved as a set? Because I can't show the set as a url either because the share method works with a url?
class ViewController: UIViewController {
//In my code I have this var from my core data entity
var pdfAdresse: PDFAdresse!
//If you press a collection view item for a long time, I create the following method
@objc func longPressPDF(_ sender: UIGestureRecognizer) {
if sender.state == UIGestureRecognizer.State.ended {
let longPressLocationPoint = sender.location(in: self.collectionView)
if let pressIndexPath = self.collectionView.indexPathForItem(at: longPressLocationPoint) {
print("\(pressIndexPath)")
let alertController = UIAlertController(title: "Menü", message: "", preferredStyle: .alert)
alertController.view.tintColor = UIColor.systemRed
// CancelPDF
let cancelAction = UIAlertAction(title: "Abbrechen", style: .cancel, handler: nil)
// Delete PDF
let deleteAction = UIAlertAction(title: "Löschen", style: .default) { (alertAction) in
let pdfFile = self.pdfAdresse.files[pressIndexPath.row]
CoreDataService.defaults.deletePDFfile(pdfFile)
self.collectionView.reloadData()
}
// Share PDF
let shareAction = UIAlertAction(title: "Teilen", style: .default) { (alertAction) in
let activityController = UIActivityViewController(activityItems: [self.pdfAdresse.files[pressIndexPath.row] as Any], applicationActivities: nil)
activityController.popoverPresentationController?.sourceView = self.view
self.present(activityController, animated: true, completion: nil)
}
alertController.addAction(cancelAction)
alertController.addAction(deleteAction)
alertController.addAction(shareAction)
present(alertController,animated: true, completion: nil)
}
}
}
}