macOS应用中自定义导出类型的ShareLink无分享选项问题
开发macOS应用时,我发现使用自定义导出类型时,SwiftUI的ShareLink无法显示任何分享选项。当前我的类型遵循public.data和public.json,同时拥有唯一标识符与文件扩展名。
附上空分享面板截图:
查阅《Uniform Type Identifiers》文档后,看到关于内容类型的说明:
对于文档类型,需直接或间接遵循public.content,此遵循可让用户通过AirDrop分享你的类型。
但这在我的场景中似乎不生效,我认为自己可能存在操作错误。
以下是我的Transferable遵循代码:
extension Quote: Transferable { static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .quote) } } extension UTType { // 实际类型标识符并非com.example static var quote: UTType { UTType(exportedAs: "com.example.quote") } }
这是我在Xcode项目设置中声明的导出类型标识符与文档类型:
我的ShareLink代码如下:
ShareLink( item: Quote(text: "In a galaxy far far away..."), preview: SharePreview("An intersting quote"), label: { Image(systemName: "square.and.arrow.up") } )
请问有人知道为何使用自定义导出类型标识符会出现无分享选项的问题吗?
内容的提问来源于stack exchange,提问作者Oscar Mann
相关产品推荐
相关产品推荐

