当用户在UITextView中touch 自动检测到的电话链接时,是否可以执行自定义操作.请不要建议改用UIWebView.
请不要只是重复apple classes reference中的文本
谢谢
当用户在UITextView中touch 自动检测到的电话链接时,是否可以执行自定义操作.请不要建议改用UIWebView.
请不要只是重复apple classes reference中的文本
谢谢
Update: From ios10,
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction;
From ios7 and Later UITextView
has the delegate method:
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange *NS_DEPRECATED_IOS(7_0, 10_0, "Use textView:shouldInteractWithURL:inRange:forInteractionType: instead");*
拦截链接的点击.这是最好的方法.
For ios6 and earlier a nice way to do this is to by subclassing UIApplication
and overwriting the -(BOOL)openURL:(NSURL *)url
@interface MyApplication : UIApplication {
}
@end
@implementation MyApplication
-(BOOL)openURL:(NSURL *)url{
if ([self.delegate openURL:url])
return YES;
else
return [super openURL:url];
}
@end
你需要在你的代表中实现openURL:
.
现在,要让应用程序从新的子类UIApplication
开始,请找到文件main.我参与了你的项目.在这个 bootstrap 应用程序的小文件中,通常有这样一行:
int retVal = UIApplicationMain(argc, argv, nil, nil);
第三个参数是应用程序的类名.因此,将这一行替换为:
int retVal = UIApplicationMain(argc, argv, @"MyApplication", nil);
这对我起了作用.