1

Currently I am only trying to do this in iOS, but I don't know where to look for how to describe an iOS file type. These are "plain text" files, but with specific odd extensions. I tried "text/plain", but that did not "light up" my files for iOS (but did allow .CSV files).

Here's the code I'm starting with...

private async void ButtonFMSPick_Clicked( object sender, EventArgs e ) {
    FilePickerFileType filePickerFileType = new FilePickerFileType(
        new Dictionary<DevicePlatform, IEnumerable<string>> {
                    { DevicePlatform.iOS, new [] { "*.ABC", "*.123" } },
                    { DevicePlatform.Android, new [] { "*.ABC", "*.123" } },
        } );

    PickOptions pickOptions = new PickOptions {
        PickerTitle = "Select all the files",
        FileTypes = filePickerFileType,
    };
    var results = await FilePicker.PickMultipleAsync(pickOptions);
    if (results == null) {
        lblFileContents.Text = "Return NULL";
        return;
    }
    lblFileContents.Text = $"  {results.Count()} files picked\r\n";
    foreach (var res in results) {
        try {
            var stream = await res.OpenReadAsync();
            lblFileContents.Text += $"File Name: {res.FileName}, len={stream.Length}, path={res.FullPath}:\r\n";
        } catch (Exception ex) {
            lblFileContents.Text += $"Exception:  {ex}";
        }
    }
}

UPDATE: I took a shot at declaring the file types -- excerpt from Info.plist below, BUT I'm very unsure about this. Now I see the ".123" file type with my app icon, but still not selectable

    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>ABC FILE</string>
            <key>LSHandlerRank</key>
            <string>Default</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.pronktech.abc</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeName</key>
            <string>123 File</string>
            <key>LSHandlerRank</key>
            <string>Default</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.pronktech.123</string>
            </array>
        </dict>
    </array>
    <key>UTExportedTypeDeclarations</key>
    <array>
        <dict>
            <key>UTTypeDescription</key>
            <string>ABC FILE</string>
            <key>UTTypeIdentifier</key>
            <string>com.pronktech.abc</string>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.data</string>
            </array>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>public.filename-extension</key>
                <array>
                    <string>ABC</string>
                    <string>abc</string>
                </array>
            </dict>
        </dict>
        <dict>
            <key>UTTypeDescription</key>
            <string>123 File</string>
            <key>UTTypeIdentifier</key>
            <string>com.pronktech.123</string>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.data</string>
            </array>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>public.filename-extension</key>
                <array>
                    <string>123</string>
                </array>
            </dict>
        </dict>
    </array>
</dict>
bobwki
  • 794
  • 6
  • 22
  • 1
    do you have those file extensions registered in info.plist? – Jason Feb 20 '21 at 22:31
  • I didn't know I had to. Is this about UTExportedTypeDeclarations? I could not find a clear explanation of how to do that. I tried something, but it did not help. – bobwki Feb 22 '21 at 18:17
  • 1
    I'm just guessing that if they're non-standard file extensions iOS isn't going to allow you to open them unless you've declared that your app supports them – Jason Feb 22 '21 at 18:34
  • I think you are right, but I think I'm still missing something. I've added my attempt to declare file types to my quesion. – bobwki Feb 23 '21 at 15:19
  • @bobwki Maybe file picker can not select custom type of file . Could you share the sample project link here? I will check in local site. – Junior Jiang Feb 25 '21 at 07:06

0 Answers0