2

I have a URL in my textview and when we click on this url it opens this url in default safari. and I want to detect this event. I also tried this

but its not working for me. can any one suggest me how i do this. Provide me a sample for this.

My application deligate is UIResponder type.

Community
  • 1
  • 1
Mitesh Khatri
  • 3,935
  • 4
  • 44
  • 67

3 Answers3

2

the other answer works as expected.

create New File, select Objective-C Class

  • Class: MyApplication
  • Subclass of: UIApplication

paste this code in the .m file:

- (BOOL)openURL:(NSURL *)url {
    if  ([self handleOpenURL:url])
        return YES;
    else
        return [super openURL:url];
}
- (BOOL)handleOpenURL:(NSURL*)url {
    NSLog(@"my url handler");
    return YES;
}

next open your main.m and change the third parameter

return UIApplicationMain(argc, argv, nil, NSStringFromClass([SampleAppDelegate class]));

to your UIApplication-subclass name

return UIApplicationMain(argc, argv, @"MyApplication", NSStringFromClass([SampleAppDelegate class]));
Community
  • 1
  • 1
  • I already try this. But when I changed the main.m file then it displaying error and application not compiled. – Mitesh Khatri Jun 17 '12 at 16:57
  • I have it tried myself before posting and ensured it is working. How did you named your custom `UIApplication` subclass? … what is the error saying? –  Jun 17 '12 at 16:59
0

Take a look at this GitHub project: MSTextView

Mat
  • 7,613
  • 4
  • 40
  • 56
  • Thanks for reply. But actually MSTextView is not a TextView. Its type of UIVIEW. I have already added textview in my application so now i do not want to replace all text view with MSTEXTVIEW. – Mitesh Khatri Jun 08 '12 at 09:09
  • Ok, so what's your problem with the first solution you've posted? – Mat Jun 08 '12 at 09:27
  • I added this in my main.m file but its not working.. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, @"MyApplication", nil); openlink method is not called. [pool release]; return retVal; – Mitesh Khatri Jun 08 '12 at 10:04
0

Assuming you just need to display a static label with links, we have a fairly powerful attributed label in Nimbus that you may wish to check out:

http://docs.nimbuskit.info/group___nimbus_attributed_label.html

The label uses CoreText and NSAttributedString, so it is built on core Apple technologies. It acts in every way like a UILabel. Here's an example of implementing the NIAttributedLabel delegate:

https://github.com/jverkoey/nimbus/blob/master/examples/attributedlabel/BasicAttributedLabel/BasicAttributedLabel/src/MashupViewController.m#L92

More info: http://nimbuskit.info/

featherless
  • 2,118
  • 19
  • 19
  • Sorry. I do not need label. I need uitextview. Bcoz i already completed application so now its not possible to change on all places. – Mitesh Khatri Jun 17 '12 at 16:59