Xamarin.Forms无法在UIDocumentInteractionController中看到打印选项

时间:2017-10-09 10:22:06

标签: xamarin.ios xamarin.forms

为什么我无法在菜单中看到我想念的打印选项

private void OpenExtrnal()
        {


            Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
            {

                UIView parentView = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
                CGRect buttonFrame = new CGRect( 0 , -260 , 320 , 320);
                var PreviewController = UIDocumentInteractionController.FromUrl(new NSUrl(localDocUrl, true));
                PreviewController.Delegate = new UIDocumentInteractionControllerDelegateClass(UIApplication.SharedApplication.KeyWindow.RootViewController);
                if(passedImage != null && Device.Idiom == TargetIdiom.Tablet){
                    buttonFrame = FormsViewToNativeiOS.ConvertFormsToNative(passedImage).Frame;
                }

                PreviewController.PresentOpenInMenu(buttonFrame , parentView ,  true);
            });
        }

委托班级

public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
    {
        UIViewController viewC;

        public UIDocumentInteractionControllerDelegateClass(UIViewController controller)
        {
            viewC = controller;
        }

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

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


    }

1 个答案:

答案 0 :(得分:1)

您必须使用PreviewController.PresentOptionsMenu代替PreviewController.PresentOpenInMenu来显示“打印”等选项。

PresentOpenInMenuPresentOptionsMenu之间的区别在于:

  
      
  • 要向用户提示一组选项,包括在其他应用中打开文件的选项,请调用presentOptionsMenuFromRect:inView:animated:presentOptionsMenuFromBarButtonItem:animated:方法。
  •   
  • 要提示用户仅在其他应用中打开该文件,请调用presentOpenInMenuFromRect:inView:animated:presentOpenInMenuFromBarButtonItem:animated:方法。
  •   

请参阅Apple文档:GrantPermissionRule