Problem with Document picker on iPad Air 2

Hello,
I have implemented document picker. Here is part of code:

        var allowedUTIs = new string[] {
            UTType.UTF8PlainText,
            UTType.PlainText,
            UTType.RTF,
            UTType.PNG,
            UTType.Text,
            UTType.PDF,
            UTType.Image,
            UTType.UTF16PlainText,
            UTType.FileURL
        };

        UIDocumentMenuViewController importMenu =
            new UIDocumentMenuViewController(allowedUTIs, UIDocumentPickerMode.Import);
        importMenu.Delegate = this;
        importMenu.ModalPresentationStyle = UIModalPresentationStyle.Popover;
        UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(importMenu, false, null);
        UIPopoverPresentationController presentationPopover = importMenu.PopoverPresentationController;
        if (presentationPopover != null)
        {
            presentationPopover.SourceView = UIApplication.SharedApplication.KeyWindow.RootViewController.View; // this.View;
            presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Down;
        }

It works fine on iPhone - I can open iCloud dialog, select file, receive array of bytes and file name. But on iPad Air2 (both emulator and device) it shows only strange grey rectangle (see attach).

The code works - at least I can receive 'Cancel' event from picker, when I press to free space (and picker lost focus, as I understand). Any suggestions?

Tagged:

Answers

  • Answer my question myself: we just need to add coordinates and size of anchor control - for ex., button, which calls picker. (x,y)=(0,0) - does not work. Or we can add screen sizes with 10% margin. So something like this:
    ...
    if (presPopover != null)
    {
    presPopover.SourceView = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
    if (dialogPosX > -1 && dialogPosY > -1 && dialogPosW > -1 && dialogPosH > -1)
    //for ex. can try hardcode (50, 50, 100, 100)
    {
    presPopover.SourceRect = new CGRect(dialogPosX, dialogPosY, dialogPosW, dialogPosH);
    }
    presPopover.PermittedArrowDirections = UIPopoverArrowDirection.Down;
    }

Sign In or Register to comment.