0

I want to disable copy/cut menu of text area to prevent export any data from application. I put following code in apps/<AppName>/iphone/native/Classes/CDVMainViewController.m file, but it didn't work. It seems canPerformAction is called when a menu appears, but cut/copy actions are not passed to this code.

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
  BOOL can = [super canPerformAction:action withSender:sender];
  if (action == @selector(cut:) || action == @selector(copy:))
  {
    can = NO;
  }
  NSLog(@"%@ for action:%@ from sender:%@.",
    can ? @"YES" : @"NO", NSStringFromSelector(action), sender);
  return can;
}

How can I disable these options?

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
Takakiyo
  • 3
  • 1
  • Did you look at other questions and answers for alternate implementations? See here: https://www.google.com/search?q=ios+disable+copy+paste&oq=ios+disable+copy+paste – Idan Adar Nov 18 '13 at 04:59
  • The answer is given here - http://stackoverflow.com/questions/5995210/disabling-user-selection-in-uiwebview – Anton Nov 18 '13 at 08:31
  • Thanks Anton. With Swizzle method (in Altaveron's reply of the entry), I've done what I wanted. By the way, why didn't my previous code work in Worklight? Do you have any idea? – Takakiyo Nov 19 '13 at 09:20
  • @Takakiyo, is this question resolved? – Idan Adar Mar 14 '14 at 08:26

1 Answers1

0

As Anton pointed out in the comments area of the question, have a look at this question for possible solutions: Disabling user selection in UIWebView

Here are a couple from it:

Via CSS:

  textarea {
      -webkit-touch-callout: none;
      -webkit-user-select: none; /* Disable selection/copy in UIWebView */
  }

Via native code (although I believe this may not be specific to the textarea, but rather to the whole app screen; but you can modify that):

 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
    {    
        if (action == @selector(copy:) ||
            action == @selector(paste:)||
            action == @selector(cut:)) 
        {
            return _copyCutAndPasteEnabled;
        }
        return [super canPerformAction:action withSender:sender];
    }
Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89