Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
[Launcher][iOS] Fixing save to files bug (#1609)
Browse files Browse the repository at this point in the history
* changed creating UIDocumentInteractionController on Launcher
* changed PlatformOpenAsync on Launcher iOS
  • Loading branch information
dimonovdd committed Jan 15, 2021
1 parent 9996ab2 commit c541cbe
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions Xamarin.Essentials/Launcher/Launcher.ios.tvos.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using CoreGraphics;
using Foundation;
using UIKit;

Expand Down Expand Up @@ -34,43 +35,22 @@ static Task<bool> 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();
Expand Down

0 comments on commit c541cbe

Please sign in to comment.