How to disable popup menu items like Select, Select All, Suggest…, Define (on UIWebView)?

前端 未结 1 540
梦如初夏
梦如初夏 2021-01-24 14:05

How to disable popup menu items like Select, Select All, Suggest..., Define (on UIWebView)?

相关标签:
1条回答
  • 2021-01-24 14:17

    Swizzle the following method:

    #import "NSObject+myCanPerformAction.h"
    
    @implementation NSObject (myCanPerformAction)
    
    - (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender {
        if (action == @selector(copy:)) {
            return [self myCanPerformAction:action withSender:sender]; // not a recursion
        }
        if (action == @selector(paste:)) {
            return [self myCanPerformAction:action withSender:sender]; // not a recursion
        }
        return NO;
    }
    
    @end
    

    Swizzling:

    [[UIWebDocumentView class] jr_swizzleMethod:@selector(canPerformAction:withSender:) withMethod:@selector(myCanPerformAction:withSender:) error:nil];
    
    0 讨论(0)
提交回复
热议问题