-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6448 from frenzibyte/ios-export-files
Add support for presenting/opening files on iOS
- Loading branch information
Showing
3 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
{ | ||
internal class IOSFilePresenter : UIDocumentInteractionControllerDelegate | ||
{ | ||
private readonly IOSWindow window; | ||
private readonly UIDocumentInteractionController viewController = new UIDocumentInteractionController(); | ||
|
||
internal IOSFilePresenter(IOSWindow window) | ||
{ | ||
this.window = window; | ||
} | ||
|
||
public bool OpenFile(string filename) | ||
{ | ||
setupViewController(filename); | ||
|
||
if (viewController.PresentPreview(true)) | ||
return true; | ||
|
||
var gameView = window.UIWindow.RootViewController!.View!; | ||
return viewController.PresentOpenInMenu(gameView.Bounds, gameView, true); | ||
} | ||
|
||
public bool PresentFile(string filename) | ||
{ | ||
setupViewController(filename); | ||
|
||
var gameView = window.UIWindow.RootViewController!.View!; | ||
return viewController.PresentOptionsMenu(gameView.Bounds, gameView, true); | ||
} | ||
|
||
private void setupViewController(string filename) | ||
{ | ||
var url = NSUrl.FromFilename(filename); | ||
|
||
viewController.Url = url; | ||
viewController.Delegate = this; | ||
|
||
if (OperatingSystem.IsIOSVersionAtLeast(14)) | ||
viewController.Uti = UTType.CreateFromExtension(Path.GetExtension(filename))?.Identifier ?? UTTypes.Data.Identifier; | ||
} | ||
|
||
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller) => window.UIWindow.RootViewController!; | ||
|
||
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. | ||
viewController.DismissMenu(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters