Search code examples
iosxamarincross-platformfilepicker

Xamarin IOS filepicker stuck


I am using xamarin.plugin.filepicker

it works fine with android. but with IOS (iPhone 6+) it did not work.

once it come to this code:

var file = await CrossFilePicker.Current.PickFile();

it stuck and does not continue, the application not freese, it works fine, but not get any result from "await CrossFilePicker.Current.PickFile();".

Even if i click "cancel" or select a file, nothing let the code go after this line:

var file = await CrossFilePicker.Current.PickFile();

There are no errors, nothing at all.

I am using the last stable version of the plugin, then I also tried "2.1.14-beta".

the question is : why the code does not go to the "if (file != null)" statement ever?

var file = await CrossFilePicker.Current.PickFile(); << Stop here

if (file != null) << Not come here ever

Thanks in advance


Solution

  • Finally, I fix the problem

    I was using javascript callback to fire the file picker event. The problem was in the html code, I used "a" object as you can see:

    <a href="#" 
            onclick="UploadImage();" 
            style="text-decoration:none;" data-ajax="false" data-role="none">
    </a>
    

    it works find on android, but stuck on IOS. I noticed that the (href="#") fires "FormswebView_OnNavigationStarted" event using IOS. this make two events fire sametime, FormswebView_OnNavigationStarted + my javascriptcallback (ShowUploadAppImagesAsync). that is why it stuck there and did not hit the next line.

    Once I changed the "a" object to "div" object, it works fine.

    <div 
            onclick="UploadImage();" 
            style="text-decoration:none;" data-ajax="false" data-role="none">
    </div>
    

    hope this can help anyone

    Thanks to "TosT" and "Jack Hua - MSFT"

    Regards