objective-c - 使用 UIDocumentPickerViewController initForOpeningContentTypes 时无法选择文件
问题描述
我正在尝试使用 iOS 14 initForOpeningContentTypes:而不是已弃用的initWithDocumentTypes:inMode:
,并且我无法访问带有扩展名的文件p8
(它们是灰色的)。
我正在尝试以下代码:
NSArray<UTType*> * contentTypes = @[[UTType typeWithFilenameExtension: @"p8"
conformingToType: UTTypeData]];
UIDocumentPickerViewController *documentPicker = nil;
documentPicker = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes: contentTypes];
选择器启动,但文件“myfile.p8”显示为灰色且无法选择。我在这里做错了什么?
解决方案
一旦我将以下内容添加到我的应用程序的 Info.plist 中,我就可以选择该文件:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>com.my-company.my-identifier</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>My Description</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>p8</string>
</array>
</dict>
</dict>
</array>
显然它告诉系统类型。有关. _ _UTExportedTypeDeclarations
推荐阅读
- python-3.x - 如何将线图添加到熊猫中的堆积条形图
- flutter - 通过 MaterialPageRoute 路由时未加载 Flutter Page 的数据,但 Hot Reloading 正确加载数据?
- r - 创建一个用于 CARBayes 的巨型矩阵而不会耗尽内存
- sql-server - SQL Server 2014 SP3 慢查询,估计行数和实际行数差异很大
- python - 如何从字典中擦除/删除大括号/大括号?
- javascript - 如何在html标签中传递数据?
- java - Reactive Redis:如果 Redis 不可用,Spring Boot 应用程序启动失败
- javascript - 如何将 vue js 用于某些 Laravel 路由,而将刀片用于其他路由?
- r - 根据索引日期之前和之后的条件生成日期
- c# - Windows 服务/SQL Server 并发问题