Closed elmernocon closed 7 years ago
public class FilePickerImplementation : NSObject, IUIDocumentMenuDelegate, IFilePicker
{
...
public void DidPickDocumentPicker (UIDocumentMenuViewController documentMenu, UIDocumentPickerViewController documentPicker)
{
...
// UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(documentPicker, true, null);
GetActiveViewController().PresentViewController(documentPicker, true, null);
}
...
private Task<FileData> TakeMediaAsync ()
{
....
// UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(importMenu, true, null);
GetActiveViewController().PresentViewController(importMenu, true, null);
...
}
private static UIViewController GetActiveViewController ()
{
UIViewController vc = UIApplication.SharedApplication.KeyWindow.RootViewController;
while (vc.PresentedViewController != null)
vc = vc.PresentedViewController;
return vc;
}
}
@elmernocon , how did you fix it? I didn't get the second comment. Where I find that code?
@riandesign , Hi, any chance you're still using the NuGet package? because that one is heavily outdated. If you are, I suggest cloning this repo and rebuilding the .DLL(s). There you'll find the FilePickerImplementation.cs for iOS. This issue seems to happen when you are presenting a view controller not from the most active view controller, you can check by calling FileData fileData = await CrossFilePicker.Current.PickFile();
from your very first page.
@elmernocon alright! Can you tell me how compile the repro GitHub and get the DLL(s)? PS: I installed it from Visual Studio, and the version is 1.2.1. Is it outdated?
@elmernocon also, in your code, what is GetActiveViewController()
?
Can you share the code, please?
@riandesign , here you go recompiling .DLL(s). GetActiveViewController() is a helper method that tries to get the most visible view controller by reiterating from the very first view controller (your main page) to the very last (your child/grandchild/grandgrandchild/grandgrandgrand... page).
@elmernocon that's the same as if I build the solution and go to \bin\iPhone\Release
, right? There'll be the DLL's file, aren't they? Or am I wrong?
@riandesign , yup.
@elmernocon I build the DLL's from this repro GitHub, but now when I build on iOS I got this:
System.Exception: Error getting value from 'DataArray' on 'Plugin.FilePicker.Abstractions.FileData'.
Xam.Plugin.FilePicker Version 1.1.0 Xamarin Forms Version 2.3.3.180 Xamarin.iOS Version 10.3
private async void PickFile () { try { FileData fileData = await CrossFilePicker.Current.PickFile(); } catch (Exception ex) {} }
2017-02-07 11:29:54.298 ProjectiOS[1363:1213422] Warning: Attempt to present <UIDocumentMenuViewController: 0x1599a6a10> on <Xamarin_Forms_Platform_iOS_PlatformRenderer: 0x157eaa060> whose view is not in the window hierarchy!