In Xamarin.Forms application, i am using displaying a file picker to user using UIDocumentPickerViewController. It has one property DirectoryUrl which can be used iOS 13.0 and above. Basically as per documentation this property sets the initially directory for file picker.
Documentation Link: https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller/3183918-directoryurl
If i set the DirectoryUrl property, then it opens up the file picker with initially set directory with browse tab selected in file picker but cancel button is not visible on top.
When user goes to recent tab and come back to browse tab then only the cancel button gets visible.
If user cancel the file picker using cancel button on recent tab, then also cancel button on browse tab will not be visible.
Code:
var allowedUtis = new string[]
{
UTType.Content,
UTType.Item,
UTType.Data
};
if (allowedTypes != null)
{
allowedUtis = allowedTypes;
}
var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Import);
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
// DirectoryUrl property only works in iOS SDK 13.0+
// _documentsPath is path for folder
docPicker.DirectoryUrl = new NSUrl(_documentsPath, true);
}
documentPicker.DidPickDocument += this.DocumentPicker_DidPickDocument;
documentPicker.WasCancelled += this.DocumentPicker_WasCancelled;
documentPicker.DidPickDocumentAtUrls += this.DocumentPicker_DidPickDocumentAtUrls;
UIViewController viewController = GetActiveViewController();
viewController.PresentViewController(documentPicker, true, null);