打印不能使用UIDocumentInteractionController?

时间:2017-03-20 15:02:02

标签: ios objective-c react-native

我使用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];
}

1 个答案:

答案 0 :(得分:0)

在.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