0

Trying to get my App to work on iOS now - and wow! This is way harder than I thought.

OK, So I have a filepicker that picks a file. pretty simple (code below.) . With iOs. The file picker dialog opens, and I can click the file I want , but nothing happens - until I hit cancel, then the code continues to run... (pickresult != null).. it is null - code stops... https://photos.app.goo.gl/fGD5SPtCqdMYE8AS7

    var customFileType =
    new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
    {
        { DevicePlatform.iOS, new[] { "com.microsoft.word.doc" } }, // or general UTType values
        { DevicePlatform.Android, new[] { "application/doc" } },
        { DevicePlatform.UWP, new[] { ".doc" } },
        { DevicePlatform.Tizen, new[] { "*/*" } },
        { DevicePlatform.macOS, new[] { "doc" } }, // or general UTType values
    });
    string OutupPath;
    var pickResult = await FilePicker.PickAsync(new PickOptions
    {
        FileTypes = customFileType,
        PickerTitle = "Select Doc File"
        
    }) ;
    if (pickResult != null)
    {
        OutupPath = pickResult.FullPath.ToString();
        App.docFilePath = OutupPath;
        LoadingText = pickResult.FileName.ToString();
        DbFileName = LoadingText;
    }
    else { 
        return;
    }

Note - I am developing on Win10 vs 2022. And I am new to iOs. I just got my apple dev account up and running. The Android version and Windows version of this work flawlessly.

Not sure where I should be looking to solve this glitch.

https://photos.app.goo.gl/fGD5SPtCqdMYE8AS7

Entitlements.plist

Original code with no options

private async void Button_Clicked(object sender, EventArgs e)
{
    var pickResult = await FilePicker.PickAsync();
    if (pickResult != null)
    {
        FileLabel.Text = pickResult.FileName.ToString();
    }
    else {
        await DisplayAlert("Alert", "No File Selected", "OK");
    }
}
Chuck
  • 21
  • 5
  • https://github.com/xamarin/Essentials/issues/1962 – Jason Mar 15 '22 at 00:11
  • Thank You. My files are not disabled or greyed out. hmmmm. They are available and clickable. There is something on the Apple side of things that is preventing the file from being picked. – Chuck Mar 15 '22 at 01:02

1 Answers1

1

What about adding org.openxmlformats.wordprocessingml.document in file types as well ?

The actual type for the file may be docx, so just have a try .

Refer to

https://learn.microsoft.com/en-us/answers/questions/362776/xamarin-file-picker-file-types-for-ios.html

https://stackoverflow.com/a/51592769/8187800

Update (specify doc type in PickOptions)

var customFileType =
    new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
    {
        { DevicePlatform.iOS, new[] { "com.microsoft.word.doc","org.openxmlformats.wordprocessingml.document" } }, // or general UTType values
        { DevicePlatform.Android, new[] { "application/doc" } },
        { DevicePlatform.UWP, new[] { ".doc" } },
        { DevicePlatform.Tizen, new[] { "*/*" } },
        { DevicePlatform.macOS, new[] { "doc" } }, // or general UTType values
    });

    var pickResult = await FilePicker.PickAsync(new PickOptions
    {
        FileTypes = customFileType,
        PickerTitle = "Select Doc File"
        
    }) ;
ColeX
  • 14,062
  • 5
  • 43
  • 240
  • Thanks, I greatly appreciate the help and the idea. My original code was just the filepicker - no options. Lets see if I can figure out how to post code in here. Nope (See orig post for original code at the bottom). – Chuck Mar 15 '22 at 10:21
  • Please check my update code . – ColeX Mar 16 '22 at 02:37
  • Thank You #ColeX I appreciate the extra help. Hopefully that will help others. My issues is not related to a type of file. I can strip the code to just the file picker, and nothing can be selected. I believe it has something to do with developing for iOs on Windows VS 2022. I have implamented iCloud, and Cloud Kit into my Apple Certs, and Container within my Provision profile, but am getting an Apple error when Building the App. Microsoft knows about this bug, and is working on it. I am hoping their fix, fixes the glitch. Thanks. – Chuck Mar 16 '22 at 13:43
  • You mentioned `Microsoft knows about this bug, and is working on it` , could you attach the related issue link ? – ColeX Mar 17 '22 at 02:27
  • Of course - I apologize. https://developercommunity.visualstudio.com/t/Cannot-load-Apple-certificates/1692185 – Chuck Mar 18 '22 at 13:43