7

I use the UIDocumentInteractionController to preview files of different types within the app. This has worked fine in the past, but when running the app on a device with iOS 13 the document is not presented. What is shown is the file name and type.

I have looked for similar questions and found this UIDocumentInteractionController showing file name and file type , not file contents

I've tried NSUrl.CreateFileUrl(FilePath, null) as the comments on that question suggest but this doesn't solve the issue.

This is what I use for opening the file and presenting the preview:

var uidic = UIDocumentInteractionController.FromUrl(new NSUrl(FilePath, true));
uidic.Delegate = new DocInteractionC(navcontroller);
uidic.PresentPreview(true);

And the controller definition:

public class DocInteractionC : UIDocumentInteractionControllerDelegate
{
    readonly UIViewController m_oParentViewController;

    public DocInteractionC(UIViewController controller)
    {
        m_oParentViewController = controller;
    }

    public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
    {
        return m_oParentViewController;
    }

    public override UIView ViewForPreview(UIDocumentInteractionController controller)
    {
        return m_oParentViewController.View;
    }
}

Is it possible this is an issue with NSUrl in Xamarin.ios for iOS 13? Any help would be much appreciated.

Saamer
  • 4,687
  • 1
  • 13
  • 55
losh
  • 85
  • 6
  • Does it work on a real device but gives the error in simulator? If so, are you able to log into iCloud in the simulator can't access iCloud Drive through the Files app? – Saamer Oct 04 '19 at 18:44
  • The issue occurs on a real iOS 13 device, though I haven't been able to debug a device running iOS 13, I only have an iOS 12 device, but I get the same behaviour that was reported in the iOS 13 simulator. – losh Oct 07 '19 at 07:14
  • Looks like the file isn't recognized correctly. If I open an XLSX file and press the share button on the top right corner it doesn't show Numbers or Excel as possible share targets. – Guido Neele Oct 07 '19 at 12:03

1 Answers1

6

My issue was solved by modifying the code as followed:

var uidic = new UIDocumentInteractionController()
{
  Name = fileName,
  Url = NSUrl.FromFilename(filePath),
  Delegate = new DocInteractionC(viewController)
};

uidic.PresentPreview(true);

Larger files, like an 11MB XLSX file, will take very long to load.

Guido Neele
  • 778
  • 1
  • 7
  • 20