当用户在UITextView中touch 自动检测到的电话链接时,是否可以执行自定义操作.请不要建议改用UIWebView.

请不要只是重复apple classes reference中的文本

谢谢

推荐答案

Update: From ,

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction;

From 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 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);

这对我起了作用.

Objective-c相关问答推荐

Asihttprequest 61 错误

使用 ARC,什么更好:alloc 或 autorelease 初始化程序?

go 掉 UISearchBar 下的 1px 边框

使用 [NSBundle mainBundle] pathForResource: ofType:inDirectory: 访问文件

有没有办法清除 UIImage 类使用的缓存?

在 iOS 设备上本地存储图像

如何调整 UIModalPresentationFormSheet 的大小?

如何编写 Objective-C 完成块

UITextView 禁用文本 Select

如何将日期字符串解析为 iOS 中的 NSDate 对象?

警告的含义在演示过程中!

在 NSNumbers 的 NSArray 中查找最小值和最大值

具有高质量代码的开源 Objective-C 项目?

发出许多网络请求的 iOS 应用程序的最佳架构?

自定义 UINavigationBar 背景

Electron邮件镇静 iOS 8

iOS 8 Mapkit Objc 无法获取用户位置

如何在 UIAlertController 中添加 textField?

每个 ivar 都必须是一个属性吗?

Xcode 7 警告:目标文件是为比链接更新的 iOS 版本构建的