From 1db444b0705f7648566d7f3080c566d415adf2f5 Mon Sep 17 00:00:00 2001 From: Emlyn Bolton Date: Sat, 30 Nov 2019 21:25:15 -0800 Subject: [PATCH] Present the file sharing on iPad in a popover - and prevent the crash. (#1145) * Present the file sharing on iPad in a popover - and prevent the crash. * Update gradle.properties --- ios/src/io/anuke/mindustry/IOSLauncher.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ios/src/io/anuke/mindustry/IOSLauncher.java b/ios/src/io/anuke/mindustry/IOSLauncher.java index 1a46baf921..7f4783d1a8 100644 --- a/ios/src/io/anuke/mindustry/IOSLauncher.java +++ b/ios/src/io/anuke/mindustry/IOSLauncher.java @@ -12,6 +12,7 @@ import io.anuke.mindustry.game.Saves.*; import io.anuke.mindustry.io.*; import io.anuke.mindustry.mod.*; import io.anuke.mindustry.ui.*; +import org.robovm.apple.coregraphics.*; import org.robovm.apple.foundation.*; import org.robovm.apple.uikit.*; import org.robovm.objc.block.*; @@ -124,7 +125,17 @@ public class IOSLauncher extends IOSApplication.Delegate{ NSURL url = new NSURL(to.file()); UIActivityViewController p = new UIActivityViewController(Collections.singletonList(url), null); - UIApplication.getSharedApplication().getKeyWindow().getRootViewController().presentViewController(p, true, () -> Log.info("Success! Presented {0}", to)); + UIViewController rootVc = UIApplication.getSharedApplication().getKeyWindow().getRootViewController(); + if(UIDevice.getCurrentDevice().getUserInterfaceIdiom() == UIUserInterfaceIdiom.Pad){ + // Set up the pop-over for iPad + UIPopoverPresentationController pop = p.getPopoverPresentationController(); + UIView mainView = rootVc.getView(); + pop.setSourceView(mainView); + CGRect targetRect = new CGRect(mainView.getBounds().getMidX(), mainView.getBounds().getMidY(), 0, 0); + pop.setSourceRect(targetRect); + pop.setPermittedArrowDirections(UIPopoverArrowDirection.None); + } + rootVc.presentViewController(p, true, () -> Log.info("Success! Presented {0}", to)); }catch(Throwable t){ ui.showException(t); }