SentTransferredFile所需Info.plist配置问题及官方文档查询
问题:FileRepresentation + SentTransferredFile 导出时,Save to Files 功能异常
场景复现
实现Transferable协议的代码如下:
extension LoanXLSX: Transferable { static var transferRepresentation: some TransferRepresentation { FileRepresentation(exportedContentType: .loan) { document in // Generate an XLSX document and retrieve its path... let url = URL(filePath: path) return SentTransferredFile(url) } } }
多数分享渠道可正常工作,但使用Save to Files时,系统弹出空白文件浏览器面板后直接关闭,应用日志输出:
cancelled request - error: The operation couldn’t be completed. Invalid argument
控制台中SaveToFiles进程关联错误:
completing requestwith error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
解决方案
开启以下任意一组配置即可修复问题:
- 同时开启
LSSupportsOpeningDocumentsInPlace与UIFileSharingEnabled(在Info.plist中添加对应布尔键并设为YES) - 仅开启
UISupportsDocumentBrowser(在Info.plist中添加对应布尔键并设为YES)
相关资源参考
苹果官方文档中,与该问题相关的核心配置说明:
UIFileSharingEnabled:控制应用是否支持iTunes文件共享,同时影响系统文件浏览器的交互权限LSSupportsOpeningDocumentsInPlace:允许应用直接打开沙盒外的文档,是文档浏览器交互的基础配置之一UISupportsDocumentBrowser:声明应用支持文档浏览器框架,开启后会自动赋予系统文件交互的必要权限
相关WWDC视频可关注:
- WWDC 2017 Session 226: Introducing the Document Browser
- WWDC 2020 Session 10652: Advances in App Clip Experiences(涉及文件交互权限部分)
- WWDC 2022 Session 10062: Share and collaborate with document-based apps
内容的提问来源于stack exchange,提问作者lucasgladding
相关产品推荐
相关产品推荐

