我试图在我的应用中从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文件是灰色的且不可选择。我究竟做错了什么?

最佳答案

您应该在文档类型列表中使用自定义的UTI:

UIDocumentPickerViewController *documentPicker =[[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.giena.Interface.obj"] inMode:UIDocumentPickerModeOpen];

关于ios - UIDocumentPickerViewController initWithDocumentTypes中的iOS自定义UTI,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44766527/

10-10 06:32