我有一个tableView,其中包含带电话号码的单元格。该应用程序没有拨号。请参见下面的代码为什么我的“tel:”链接不能正常工作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 2) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *numberToDial = [NSString stringWithFormat:@"tel:%@", selectedCell.detailTextLabel.text];
NSLog(@"%@",numberToDial);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:numberToDial]];
}
}
控制台输出中: 2010-03-08 01:32:30.830 AIB[1217:207] tel:01 8350098
正如你所看到的,这个数字到控制台,但没有得到拨号。奇怪的是,如果我改变的最后一个语句这样:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:171"]];
电话拨打此号码171,没有任何问题
,如在以下建议我的特定问题的解决方案,从电话号码中删除空格。我做到这一点如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 2) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSMutableString *numberToDial = [NSMutableString stringWithFormat:@"tel:%@", selectedCell.detailTextLabel.text];
[numberToDial replaceOccurrencesOfString:@" "
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [numberToDial length])];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:numberToDial]];
}
}