问题描述
我正在尝试在我的应用中从iCloud驱动器中打开.obj文件,并抛出UIDocumentPickerViewController.我找不到.obj文件的标准UTi.因此,使用此 https://developer.apple.com/library/content/qa/qa1587/_index.html 我尝试为我的应用添加对此文件扩展名的支持.
I am trying to open .obj files from iCloud drive in my app throw UIDocumentPickerViewController. I could't find standart UTi for .obj files. So, using this https://developer.apple.com/library/content/qa/qa1587/_index.html I try to add support of this file-extension for my app.
有info.plist部分:
there is info.plist sections :
<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>
有UIDocumentPickerViewController调用:
and there is UIDocumentPickerViewController call:
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.text"] inMode:UIDocumentPickerModeOpen];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];
当我运行应用程序时,我会看到用于选择文件的弹出视图,但是.obj文件是灰色的并且无法选择.我在做什么错了?
When i am running app, i see popup view for file choosing, but .obj files is grey and not-selectable. What am i doing wrong?
推荐答案
您必须输入以下内容:
<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>
和
<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>
还需要在控制器中输入以下内容:
Also in your controller you have to put something like this:
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.giena.Interface.document.obj"], in: .import)
应该可以
这篇关于UIDocumentPickerViewController initWithDocumentTypes中的iOS自定义UTI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!