diff --git a/Xamarin.Essentials/Launcher/Launcher.ios.tvos.cs b/Xamarin.Essentials/Launcher/Launcher.ios.tvos.cs index 2bbaa3bda..67d4c4c00 100644 --- a/Xamarin.Essentials/Launcher/Launcher.ios.tvos.cs +++ b/Xamarin.Essentials/Launcher/Launcher.ios.tvos.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Threading.Tasks; +using CoreGraphics; using Foundation; using UIKit; @@ -34,43 +35,22 @@ static Task PlatformTryOpenAsync(Uri uri) static Task PlatformOpenAsync(OpenFileRequest request) { - var fileUrl = NSUrl.FromFilename(request.File.FullPath); - - documentController = UIDocumentInteractionController.FromUrl(fileUrl); - documentController.Delegate = new DocumentControllerDelegate + documentController = new UIDocumentInteractionController() { - DismissHandler = () => - { - documentController?.Dispose(); - documentController = null; - } + Name = request.File.FileName, + Url = NSUrl.FromFilename(request.File.FullPath), + Uti = request.File.ContentType }; - documentController.Uti = request.File.ContentType; - - var vc = Platform.GetCurrentViewController(); - - CoreGraphics.CGRect? rect = null; - if (DeviceInfo.Idiom == DeviceIdiom.Tablet) - { - rect = new CoreGraphics.CGRect(new CoreGraphics.CGPoint(vc.View.Bounds.Width / 2, vc.View.Bounds.Height), CoreGraphics.CGRect.Empty.Size); - } - else - { - rect = vc.View.Bounds; - } - documentController.PresentOpenInMenu(rect.Value, vc.View, true); + var view = Platform.GetCurrentUIViewController().View; + var rect = DeviceInfo.Idiom == DeviceIdiom.Tablet + ? new CGRect(new CGPoint(view.Bounds.Width / 2, view.Bounds.Height), CGRect.Empty.Size) + : view.Bounds; + documentController.PresentOpenInMenu(rect, view, true); return Task.CompletedTask; } - class DocumentControllerDelegate : UIDocumentInteractionControllerDelegate - { - public Action DismissHandler { get; set; } - - public override void DidDismissOpenInMenu(UIDocumentInteractionController controller) - => DismissHandler?.Invoke(); - } #else static Task PlatformOpenAsync(OpenFileRequest request) => throw new FeatureNotSupportedException();