I also stumbled upon this problem and it really is frustrating. I donβt remember exactly where I got the solution from, but this is the following; getSelection() returns a JavaScript object that cannot be converted to a string. You must explicitly convert it to a string from JavaScrtipt code:
NSString *highlighted = [_webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString();"];
Look in action.
user529758
source share