【问题标题】:Printing not working with UIDocumentInteractionController?打印无法使用 UIDocumentInteractionController?
【发布时间】:2017-03-20 15:02:02
【问题描述】:

我正在使用UIDocumentInteractionController 查看 PDF。当我打开 PDF 时,单击右上角带有向上箭头的正方形,然后选择打印什么也没有发生。知道如何解决这个问题吗?

这是我的代码:

UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:path];
interactionController.delegate = self;
dispatch_sync(dispatch_get_main_queue(), ^{
    [interactionController presentPreviewAnimated:YES];
});

更新:

我忘了提,我还有下面的代码,因为没有它,状态栏会显示在文档预览菜单栏上。我必须添加以下代码,因为我的应用程序始终隐藏状态栏,并且当文档预览打开时状态栏覆盖菜单栏时没有它。如果我删除代码,打印功能就可以正常工作......

- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
{
    [[[[UIApplication sharedApplication] delegate] window] setWindowLevel:UIWindowLevelStatusBar];

    return [[[[UIApplication sharedApplication] delegate] window] rootViewController];
}

【问题讨论】:

    标签: ios objective-c react-native


    【解决方案1】:

    在您的 .h 文件中添加这一行:

    @property (strong, nonatomic) UIDocumentInteractionController *documentInteractionController;
    

    这些到你的 .m 文件中:

    self.documentInteractionController= [UIDocumentInteractionController interactionControllerWithURL:url];
    
    //set delegate
    
    [self.documentInteractionController setDelegate:self];
    
    //provide button's frame from where popover will be lauched
    
    [self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
    

    参考:

    https://stackoverflow.com/a/15664394/5184217

    【讨论】:

    • 我尝试了该代码并没有解决问题,但我发现了更多细节。我添加了更多代码和更新。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 2019-08-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多