How to open UITextView web links in a UIWebView instead of Safari?

crash picture crash · Aug 20, 2009 · Viewed 8k times · Source

I'm developing and iPhone 3.0 application. And I'm trying to open web links in a UITextView into a UIWebView instead of Safari. But still no luck.

The UITextView is not editable, and it perfectly detects web links and open them in Safari.

How to avoid that? How to grab that url so i can use with my own UIWebView?

Answer

nihad picture nihad · Nov 17, 2013

This is an old question but incase anyone is looking for an updated way of doing this.

Assign your viewController that holds the UITextView as a delegate in your viewController's .m file and just add:

-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{

    //Do something with the URL
    NSLog(@"%@", URL);


    return NO;
}