alinz / react-native-webview-bridge

React Native Webview with Javascript Bridge
MIT License
1.37k stars 493 forks source link

How to use a UIWebView with added category instead? #274

Open ethanyuwang opened 5 years ago

ethanyuwang commented 5 years ago

I need to disable copy and cut and have found this post: https://stackoverflow.com/a/11290826/8710951

I have created a category file as instructed:

UIWebView+DisableCopy.h

#import <UIKit/UIKit.h>

@interface UIWebView (DisableCopy)
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender;
@end

UIWebView+DisableCopy.m

#import "UIWebView+DisableCopy.h"

@implementation UIWebView (DisableCopy)

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

@end

Then I imported this file in RCTWebViewBridge.m: #import "UIWebView+DisableCopy.h"

However, the above approach has taken no effect. I have zero knowledge about objective C. What would be the correct way to do this?