IOS Opening Files - PresentOpenInMenu - Selection failing if not tapped right away

rfingerhuthrfingerhuth ✭✭Member ✭✭

Have a Xamarin Forms project that has a document page that ideally would allow the user to select a document and open it in different app of their choice.

Wondering if anyone else has experienced this,

Currently grabbing file data from a web service, and then writing it locally. Then using UIDocumentInteractionController to present options for different apps that could open the file.

If the user doesn't tap on one of the apps within the OpenInMenu when it appears it won't end up opening the file in that app.

But if they tap on the app right away it will open up in that app.

So if they were to wait 2 seconds and then select an app, it would simply dismiss the OpenInMenu and do nothing.

So I have this code below executing in an iOS Dependency

var nsUri = NSUrl.FromFilename(fullPath);
var viewer = UIDocumentInteractionController.FromUrl(nsUri);
var controller = GetVisibleViewController();
var result = viewer.PresentOpenInMenu(new RectangleF(0, -260, 320, 320), controller.View, true);
return result;

Here is the GetVisibleViewController Method:

    private UIViewController GetVisibleViewController(UIViewController controller = null) {
        controller = controller ?? UIApplication.SharedApplication.KeyWindow.RootViewController;

        if (controller.PresentedViewController == null)
            return controller;

        if (controller.PresentedViewController is UINavigationController) {
            return ((UINavigationController)controller.PresentedViewController).VisibleViewController;
        }

        if (controller.PresentedViewController is UITabBarController) {
            return ((UITabBarController)controller.PresentedViewController).SelectedViewController;
        }

        return GetVisibleViewController(controller.PresentedViewController);
    }

Has anyone experienced this before? or have any idea if there is something on my end I can do to fix this?

Sign In or Register to comment.