iOS自定义UTI中的UidocumentPickerviewController initwithDocumentTy



我正在尝试从我的应用程序中的iCloud drive打开.obj文件。我找不到.OBJ文件的Standart UTI。因此,使用此https://developer.apple.com/library/content/qa/qa1587/_index.html我尝试添加对我的应用程序的文件 - extension的支持。

有信息。平台部分:

<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 Call:

 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];

您必须放置这样的东西:

<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)

它应该工作

最新更新