1

I'm implementing a link in a UITextView, which will push a view controller on the navigation controller.

I'm trying to use the following method:

directionTextLabel.text = [directionTextLabel.text stringByAppendingString:[[NSString alloc] initWithFormat:@" %@", siteURL]];
directionTextLabel.dataDetectorTypes = UIDataDetectorTypeLink;

Which makes my link clickable. And then in my application delegate, I have:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    NSLog(@"URL detected.");
    return 1;
}

However, when I click on the link, it opens a new page without calling my app delegate method. Any idea what's going wrong, or other way I could implement that?

Thank you.

ratsimihah
  • 1,010
  • 1
  • 11
  • 22

2 Answers2

1

The application:openURL... delegate method is intended for when your application needs to respond to its registered URL handler(s) (as defined in your Info.plist file). The URL event will be sent to the similar method in the target application (for example Safari for http links).

EDIT: See this post

Community
  • 1
  • 1
Krumelur
  • 31,081
  • 7
  • 77
  • 119
  • Do you know of any method that handles URL calls within an class? – ratsimihah Jul 30 '12 at 21:26
  • Actually, I do. and I think I realize why you got to this solution. You need to subclass the Application class and override the similarly named method. See [this post](http://stackoverflow.com/questions/2543967/how-to-intercept-click-on-link-in-uitextview). – Krumelur Jul 30 '12 at 21:27
  • This post looks great! Thanks, I'll look at it, and get back to you. – ratsimihah Jul 30 '12 at 21:33
  • Oh god, subclassing UIApplication seems like overkill. – ratsimihah Jul 30 '12 at 21:59
  • Agreed, but `UITextView` does not seem to provide a delegate method to catch those events. (EDIT: At least not if you want to avoid private APIs) – Krumelur Jul 30 '12 at 22:06
1

This method doesn't do what you think it does. This method gets called when your application is invoked by some URL scheme, and not when your app opens an URL.