xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.53k stars 505 forks source link

[Bug] FilePicker doesn't allow picking any files on iOS #2050

Closed EpEthan closed 1 year ago

EpEthan commented 1 year ago

Description

I need to import CSV/SQLite3 files in my app. I use Xamarin.Essentials.FilePicker and it works perfectly on Android, however when trying it on iOS all the files are greyed-out and I can't select any file.

I use the following file types for Android and iOS:

var customFileType =
    new Xamarin.Essentials.FilePickerFileType(new Dictionary<Xamarin.Essentials.DevicePlatform, IEnumerable<string>>
    {
        { Xamarin.Essentials.DevicePlatform.iOS, new string[] {
            "public.comma-separated-values-text",
            "text/csv",
            "comma-separated values",
            "CSV document",
            "csv",
            "public.database",
            "application/x-sqlite3",
            "application/vnd.sqlite3",
            "application/octet-stream",
        } },
        { Xamarin.Essentials.DevicePlatform.Android, new string[] {
            "text/csv",
            "Comma-separated values",
            "CSV document",
            "application/x-sqlite3",
            "application/vnd.sqlite3",
            "application/octet-stream"
        } },
    }) ;

I've also tried adding text/plain for picking CSV files on iOS and it didn't work. In addition, I've tried selecting PDF files using pdf and it didn't work.

StackOverflow Thread

Expected Behavior

File-picking dialog shows relevant files (CSV/SQLite3) not greyed out, and they're clickable.

Actual Behavior

File-picking dialog does not allow to pick any file in iOS.

Basic Information

Screenshots

Screenshot_12 Screenshot_13

jfversluis commented 1 year ago

On iOS you will have to use the UTType or the reverse domain identifier for these files, see also the example here

Here is a list as given by Apple that are built-in, yours might be a custom one.

EpEthan commented 1 year ago

I am aware of the MobileCoreServices.UTType. I've tried using MobileCoreServices.UTType.CommaSeparatedText (resolves to "public.comma-separated-values-text") as well as MobileCoreServices.UTType.Database (resolves to "public.database") and neither worked. I wrote their plaintext versions to be more comprehensive.

EpEthan commented 1 year ago

@jfversluis, I would appreciate if you re-open the bug and check it out