Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preview document using UIDocumentInteractionController doesn't work in iOS 13

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.

like image 385
losh Avatar asked Oct 04 '19 15:10

losh


1 Answers

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.

like image 116
Guido Neele Avatar answered Jan 30 '23 11:01

Guido Neele