views:

568

answers:

5

Is it possible to perform custom action when user touch autodetected phone link in UITextView. Please do not advice to use UIWebView instead.

And please don't just repeat text from apple classes reference - certainly I've already read it.

Thanks.

+1  A: 

I do not think thats possible.

The UITextView Class Reference states the following about the dataDetectorTypes property: "You can use this property to specify the types of data (phone numbers, http links, and so on) that should be automatically converted to clickable URLs in the text view. When clicked, the text view opens the application responsible for handling the URL type and passes it the URL."

It does not mention any event.

Neither does the UITextViewDelegate Protocol Reference mention any selectors that will be called upon such an event.

submachine
Thanks, but don't you think I've alredy read class reference before asking this question?
Vladimir
A: 

I haven't tried that myself but you can try to implement application:handleOpenURL: method in your application delegate - it looks like all openURL request pass through this callback.

Vladimir
A: 

Not sure how you would intercept the detected data link, or what type of function you need to run. But you may be able to utilize the didBeginEditing TextField method to run a test/scan through the textfield if you know what your looking for..such as comparing text strings that meet ###-###-#### format, or begin with "www." to grab those fields, but you would need to write a little code to sniff through the textfields string, reconize what you need, and then extract it for your function's use. I don't think this would be that difficult, once you narrowed down exactly what it is that you wanted and then focussed your if() statement filters down to very specific matching pattern of what you needed.

Of couse this implies that the user is going to touch the textbox in order to activate the didBeginEditing(). If that is not the type of user interaction you were looking for you could just use a trigger Timer, that starts on ViewDidAppear() or other based on need and runs through the textfields string, then at the end of you run through the textfield string methods that you built, you just turn the Timer back off.

Newbyman
A: 

application:handleOpenURL: is called when another app opens your app by opening a URL with a scheme your app supports. It's not called when your app begins opening a URL.

I think the only way to do what Vladimir wants is to use a UIWebView instead of a UITextView. Make your view controller implement UIWebViewDelegate, set the UIWebView's delegate to the view controller, and in the view controller implement webView:shouldStartLoadWithRequest:navigationType: to open [request URL] in a view instead of quitting your app and opening it in Mobile Safari.

A. Jesse Jiryu Davis
A: 

You might want to check this link: http://stackoverflow.com/questions/1172070/just-how-to-you-use-ttstyledtextlabel

It uses a TTStyleTextLabel (from the Three20 lib).

Neoraptor