UIDocumentPickerViewController initWithDocumentTypes中的iOS自定义UTI
我正在尝试在我的应用程序UIDocumentPickerViewController中从iCloud驱动器打开.obj文件。我找不到.obj文件的标准UTi。因此,我尝试使用它为我的应用程序添加此文件扩展名的支持 有info.plist部分:UIDocumentPickerViewController initWithDocumentTypes中的iOS自定义UTI,ios,info.plist,uti,Ios,Info.plist,Uti,我正在尝试在我的应用程序UIDocumentPickerViewController中从iCloud驱动器打开.obj文件。我找不到.obj文件的标准UTi。因此,我尝试使用它为我的应用程序添加此文件扩展名的支持 有info.plist部分: <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeIconFiles</key>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>arrow1</string>
</array>
<key>CFBundleTypeName</key>
<string>OBJ model</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.giena.Interface.obj</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>OBJ model</string>
<key>UTTypeIdentifier</key>
<string>com.giena.Interface.obj</string>
<key>UTTypeSize320IconFile</key>
<string>arrow1</string>
<key>UTTypeSize64IconFile</key>
<string>arrow1</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>obj</string>
</array>
</dict>
</dict>
</array>
当我运行应用程序时,我会看到文件选择的弹出视图,但.obj文件是灰色的,不可选择。我做错了什么?您应该在文档类型列表中使用自定义UTI:
UIDocumentPickerViewController *documentPicker =[[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.giena.Interface.obj"] inMode:UIDocumentPickerModeOpen];
你必须这样写:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>OBJ model</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>obj</string>
</array>
</dict>
</array>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>Obj file</string>
<key>LSItemContentTypes</key>
<array>
<string>com.giena.Interface.document.obj</string>
</array>
</dict>
</array>
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.giena.Interface.document.obj"], in: .import)
它应该能工作它看起来像一个bug。。。今天,我尝试使用虚拟文件扩展名.tst和.xxxx执行此操作,并且工作正常。但是对于.obj扩展名,我有一个问题。您试图选择.obj文件,但在文档类型中提到了“public.text”。如果你解决了这个问题,那么你能告诉我定制扩展的确切情况吗。
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>OBJ model</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>com.giena.Interface.document.obj</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>obj</string>
</array>
</dict>
</dict>
<dict/>
</array>
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.giena.Interface.document.obj"], in: .import)