I have read several solutions on stackoverflow of which none work for iOS 8.1 I managed to disable a long press from this uiwebview-without-copy-paste-when-displaying-pdf-files but I can't get the popup which offers :"Open", "Add to Reading List" and "Copy" from URLs disabled.
//NSURL *url = [NSURL URLWithString:@"http://www.google.com/somePdf.pdf"];
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
self.mainWebView.mediaPlaybackRequiresUserAction = NO;
[self.mainWebView.scrollView setBounces:NO];
self.mainWebView.allowsInlineMediaPlayback = YES;
self.mainWebView.delegate = self;
//NSString * jsCallBack = @"window.getSelection().removeAllRanges();";
//[self.mainWebView stringByEvaluatingJavaScriptFromString:jsCallBack];
[self.mainWebView setMultipleTouchEnabled:YES];
[self.mainWebView setScalesPageToFit:YES];
[self.mainWebView loadRequest:requestURL];
UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:nil]; // allocating the UILongPressGestureRecognizer
longPress.allowableMovement=100; // Making sure the allowable movement isn't too narrow
longPress.minimumPressDuration=0.3; // This is important - the duration must be long enough to allow taps but not longer than the period in which the scroll view opens the magnifying glass
longPress.delegate=self; // initialization stuff
longPress.delaysTouchesBegan=YES;
longPress.delaysTouchesEnded=YES;
longPress.cancelsTouchesInView=YES; // That's when we tell the gesture recognizer to block the gestures we want
[self.mainWebView addGestureRecognizer:longPress]; // Add the gesture recognizer to the view and scroll view then release
[[self.mainWebView scrollView] addGestureRecognizer:longPress];
I have tested it on some random pdf, and the pdf text is not selectable thanks to the longPress gesture recognizer. However on a normal site it still allows the copy popup.
I will try to edit the web page with this changeing web page settings but the answer is 3 years old...
Maybe I am on a whole wrong track? Should I try using a WKWebView?