2

我有UIDocumentPickerViewController以下代码:

UIDocumentPickerViewController *documentPicker =
    [[UIDocumentPickerViewController alloc] initWithDocumentTypes: @[@"public.text", @"public.sql"]
                                                               inMode: UIDocumentPickerModeOpen];

documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController: documentPicker
                   animated: YES
                 completion: nil];

这会打开选择器,我可以选择 .txt 文件,但不能选择 .sql 文件。以下屏幕截图显示了 .sql 文件在选取器中的外观。

UIDocumentPickerViewController 文件被禁用

我已将以下内容添加到我的info.plist文件中,据我了解可能需要这些内容(忽略 UTTypeReferenceURL,我只是想让它工作。)

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.sql</string>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>SQL statement(s)</string>
        <key>UTTypeIconFile</key>
        <string>public.sql</string>
        <key>UTTypeIdentifier</key>
        <string>public.sql</string>
        <key>UTTypeReferenceURL</key>
        <string>http://www.w3.org/Graphics/JPEG/</string>
    </dict>
</array>

我需要做什么才能UIDocumentPickerViewController允许选择 .sql 文件类型?

4

2 回答 2

1

我能够根据此处的另一个问题弄清楚。我在 info.plist 中添加了以下内容:

<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>SQL statements</string>
        <key>UTTypeIdentifier</key>
        <string>com.hankinsoft.sqlpro.sql</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>sql</string>
        </dict>
    </dict>
</array>

并将我UIDocumentPickerViewController的修改如下:

UIDocumentPickerViewController *documentPicker =
    [[UIDocumentPickerViewController alloc] initWithDocumentTypes: @[@"com.hankinsoft.sqlpro.sql"]
                                                           inMode: UIDocumentPickerModeOpen];
于 2017-10-18T12:01:41.630 回答
0

您必须使用public.database.public.sql

于 2017-10-17T19:14:43.880 回答