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

huangapple go评论101阅读模式
英文:

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

问题

[ShareSheet] 在 iPad 上使用文件 URL 共享时,控制台中会出现以下错误消息:

"Failed to request default share mode for fileURL:..."

在共享完成处理程序中没有报告错误。在 iPhone 上以及在 iPad 分屏视图中,它可以正常工作。

代码如下:

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)

我期望它能在全屏模式和分屏模式下正常工作。

英文:

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.

答案1

得分: 1

问题实际上不在于文件的访问,尽管错误消息中似乎是这样认为的。iPad 上共享弹出窗口的视图锚点必须正确设置。

因此,定义锚点的那一行应该如下所示:(我在其中使用了导航栏和其中的一个 barButtonItem。)

avc.popoverPresentationController?.barButtonItem = barButtonItem

也许这对其他人有所帮助,尤其是错误消息通常不太有帮助。

英文:

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.

huangapple
  • 本文由 发表于 2023年4月11日 00:23:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75978814.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定