当我用UIDocumentInteractionController打开时,如何删除文档中的副本和定义?

时间:2022-04-20 06:10:38

problem statement: preventing the copy (copying text) functionality in iOS app Document/PDF Viewer (.pdf, .doc, .docx, .txt & etc).

问题陈述:阻止iOS应用程序文档/ PDF查看器(.pdf,.doc,.docx,.txt等)中的复制(复制文本)功能。

Description: Currently, We are developing an iOS app. as a part of app requirement we need to restrict the copy functionality. I am using UIDocumentInteractionController for previewing files (.pdf, .doc, .docx, .txt & etc) in my app. While previewing the file we need to restrict the copy (copying text) functionality.

描述:目前,我们正在开发iOS应用程序。作为应用程序需求的一部分,我们需要限制复制功能。我正在使用UIDocumentInteractionController在我的应用程序中预览文件(.pdf,.doc,.docx,.txt等)。在预览文件时,我们需要限制复制(复制文本)功能。

当我用UIDocumentInteractionController打开时,如何删除文档中的副本和定义?

1 个解决方案

#1


1  

You should overrides the canPerformAction:withSender: method to return NO for actions that you don't want to allow:

您应该覆盖canPerformAction:withSender:方法,以便为您不希望允许的操作返回NO:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:))
        return NO;
    if (action == @selector(copy:))   
        return NO;
    if (action == @selector(select:))   
        return NO;    
    if (action == @selector(selectAll:))   
        return NO;  
    return [super canPerformAction:action withSender:sender];
}

OR you can try this also

或者你也可以试试这个

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    if (menuController) {
        [UIMenuController sharedMenuController].menuVisible = NO;
    }
    return NO;
}

Hope this works for you. :)

希望这对你有用。 :)

#1


1  

You should overrides the canPerformAction:withSender: method to return NO for actions that you don't want to allow:

您应该覆盖canPerformAction:withSender:方法,以便为您不希望允许的操作返回NO:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:))
        return NO;
    if (action == @selector(copy:))   
        return NO;
    if (action == @selector(select:))   
        return NO;    
    if (action == @selector(selectAll:))   
        return NO;  
    return [super canPerformAction:action withSender:sender];
}

OR you can try this also

或者你也可以试试这个

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    if (menuController) {
        [UIMenuController sharedMenuController].menuVisible = NO;
    }
    return NO;
}

Hope this works for you. :)

希望这对你有用。 :)