1

I create a DocumentInteractionViewController for preview the files when I click on share icon then on save to files option after that If i save or cancel it gives this error in iPhone 7 size devices .

Objective-C exception thrown.  Name: UIApplicationInvalidInterfaceOrientation Reason: preferredInterfaceOrientationForPresentation 'unknown' must match a supported interface orientation: 'portrait, landscapeLeft, landscapeRight, portraitUpsideDown'!

It works fine in ipad or iphone Xr.

public class DocumentInteractionViewController
    {
        private UIDocumentInteractionController _documentInteractionController;

        public DocumentInteractionViewController(string url)
        {
            if (!url.Contains(AppConstant.Protocols.File))
            {
                url = $"{AppConstant.Protocols.File}{url}";
            }

            _documentInteractionController = new UIDocumentInteractionController
            {
                Url = new NSUrl(Uri.EscapeUriString(url))
            };
        }

        public void PresnetPreview(UIViewController viewController)
        {
            viewController = viewController.NavigationController ?? viewController;
            viewController.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
            _documentInteractionController.RectangleForPreview = (e) => viewController.View.Frame;
            _documentInteractionController.ViewControllerForPreview = (e) => viewController;

            if (!_documentInteractionController.PresentPreview(true))
            {
                PresentOptionsMenu(viewController.View);
            }
        }

        public void PresentOptionsMenu(UIView view)
        {
            _documentInteractionController.PresentOptionsMenu(view.Frame, view, true);
        }
    }
Marwen Doukh
  • 1,946
  • 17
  • 26
  • 1
    Try the solution in this [thread](https://forums.xamarin.com/discussion/149525/dismissviewcontroller-causes-app-to-crash-blaming-unknown-orientation) to see if it works. – nevermore May 15 '19 at 08:25

0 Answers0