我正在尝试在我的应用程序中从 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];
当我运行应用程序时,我看到用于文件选择的弹出 View ,但 .obj 文件是灰色的且不可选择。我做错了什么?
您应该在文档类型列表中使用您的自定义 UTI:
UIDocumentPickerViewController *documentPicker =[[UIDocumentPickerViewController alloc] initWithDocumentTypes[@"com.giena.Interface.obj"] inMode:UIDocumentPickerModeOpen];
关于UIDocumentPickerViewController initWithDocumentTypes 中的 iOS 自定义 UTI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44766527/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |