When I shared a file by its URL on an iPad the following error message appears in the console:
[ShareSheet] Failed to request default share mode for fileURL:...
An error is not reported in the sharing completion handler. It works correctly on iPhone and in iPad split view.
The code looks like this:
let avc = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
avc.popoverPresentationController?.sourceView = self.view
let h: UIActivityViewController.CompletionWithItemsHandler = { [weak self] (type: UIActivity.ActivityType?, completed: Bool, modifiedItems: [Any]?, error: Error?) -> Void in
self?._handleShareResponse(completed: completed, error: error)
}
avc.completionWithItemsHandler = h
self.present(avc, animated: true, completion: nil)
I expected it to work in full screen mode as well as in split view mode.
The problem is actually not the access to the file, as is lead to believe by the error message. The view anchor for the sharing popup has to be set correctly on iPad.
So the line which defines the anchor should look like this: (I used a navigation bar and a barButtonItem in it.)
avc.popoverPresentationController?.barButtonItem = barButtonItem
Maybe this helps others especially the error message is very unhelpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With