1

当我单击共享图标然后单击保存到文件选项时,我创建了一个 DocumentInteractionViewController 用于预览文件,然后如果我保存或取消它会在 iPhone 7 大小的设备中出现此错误。

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

它在 ipad 或 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);
        }
    }
4

0 回答 0