#pragma mark - <识手机号>
- (void)validPhoneNumFromString:(NSString*)string {
NSError*error;
//根据检测的类型初始化
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypePhoneNumber error:&error];
//获得检测所得到的数组
NSRange stringRange =NSMakeRange(0, string.length);
NSArray *matches = [detector matchesInString:string options:0 range:stringRange];
for(NSTextCheckingResult *match in matches) {
if (match.resultType == NSTextCheckingTypePhoneNumber) {
NSRange phoneRange = [match range];
_phoneStr = [string substringWithRange:phoneRange];
if(_phoneStr.length>0) {
_bubbleView.textLabel.userInteractionEnabled = YES;
UITapGestureRecognizer*tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(phoneLink)];
[_bubbleView.textLabeladdGestureRecognizer:tap];
}
}
}
}
#pragma mark - 点击拨打电话
- (void)phoneLink {
NSMutableString *phone = [[NSMutableString alloc] initWithFormat:@"tel:%@",_phoneStr];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:phone]];
}