我试图在我的应用程序中从iCloud驱动器打开.obj文件,抛出UIDocumentPickerViewController。我找不到.obj文件的标准UTi。因此,使用此https://developer.apple.com/library/content/qa/qa1587/_index.html我尝试为我的应用添加对此文件扩展名的支持。
有info.plist部分:
<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调用:
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.text"] inMode:UIDocumentPickerModeOpen];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];
当我运行应用程序时,我会看到文件选择的弹出视图,但.obj文件是灰色且无法选择。我做错了什么?
答案 0 :(得分:0)
您应该在文档类型列表中使用自定义UTI:
UIDocumentPickerViewController *documentPicker =[[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.giena.Interface.obj"] inMode:UIDocumentPickerModeOpen];
答案 1 :(得分:0)
您必须输入以下内容:
<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>
还需要在控制器中输入以下内容:
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.giena.Interface.document.obj"], in: .import)
应该可以