Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing a file on iPad fails with "[ShareSheet] Failed to request default share mode for fileURL:..."

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.

like image 342
Annett Schwarze Avatar asked Sep 11 '25 03:09

Annett Schwarze


1 Answers

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.

like image 137
Annett Schwarze Avatar answered Sep 13 '25 17:09

Annett Schwarze