2

I have a UIDocumentPickerViewController with the following code:

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

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

This opens the picker and I can pick .txt files, but I cannot pick .sql files. The following screenshot shows what a .sql file looks like in the picker.

UIDocumentPickerViewController files disabled

I've added the following to my info.plist file which to my understanding may be needed (ignore the UTTypeReferenceURL, I'm just trying to get this to work.)

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

What do I need to do to have UIDocumentPickerViewController allow picking .sql file types?

Kyle
  • 17,317
  • 32
  • 140
  • 246

2 Answers2

1

I was able to figure it out based on another question here. I added the following to my 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>

And modified my UIDocumentPickerViewController to be as follows:

UIDocumentPickerViewController *documentPicker =
    [[UIDocumentPickerViewController alloc] initWithDocumentTypes: @[@"com.hankinsoft.sqlpro.sql"]
                                                           inMode: UIDocumentPickerModeOpen];
Kyle
  • 17,317
  • 32
  • 140
  • 246
0

You have to use public.database in place of public.sql.

Vini App
  • 7,339
  • 2
  • 26
  • 43
  • `public.database` does not resolve the issue either. I'm thinking that may be for sqlite database files rather than sql scripts. – Kyle Oct 17 '17 at 22:43