-
Notifications
You must be signed in to change notification settings - Fork 425
/
Copy pathIOSFilePresenter.cs
61 lines (48 loc) · 2.15 KB
/
IOSFilePresenter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.IO;
using Foundation;
using UIKit;
using UniformTypeIdentifiers;
namespace osu.Framework.iOS
{
public class IOSFilePresenter : UIDocumentInteractionControllerDelegate
{
private readonly IIOSWindow window;
private readonly UIDocumentInteractionController documentInteraction = new UIDocumentInteractionController();
public IOSFilePresenter(IIOSWindow window)
{
this.window = window;
}
public bool OpenFile(string filename)
{
setupViewController(filename);
if (documentInteraction.PresentPreview(true))
return true;
var gameView = window.ViewController.View!;
return documentInteraction.PresentOpenInMenu(gameView.Bounds, gameView, true);
}
public bool PresentFile(string filename)
{
setupViewController(filename);
var gameView = window.ViewController.View!;
return documentInteraction.PresentOptionsMenu(gameView.Bounds, gameView, true);
}
private void setupViewController(string filename)
{
var url = NSUrl.FromFilename(filename);
documentInteraction.Url = url;
documentInteraction.Delegate = this;
if (OperatingSystem.IsIOSVersionAtLeast(14))
documentInteraction.Uti = UTType.CreateFromExtension(Path.GetExtension(filename))?.Identifier ?? UTTypes.Data.Identifier;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller) => window.ViewController;
public override void WillBeginSendingToApplication(UIDocumentInteractionController controller, string? application)
{
// this path is triggered when a user opens the presented document in another application,
// the menu does not dismiss afterward and locks the game indefinitely. dismiss it manually.
documentInteraction.DismissMenu(true);
}
}
}