I have a tableView which has cells with phone numbers. The app is not dialing the numbers though. See the code below
- (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]];
}
}
Console ouput:
2010-03-08 01:32:30.830 AIB[1217:207] tel:01 8350098
As you can see, the number goes to the console, but doesn't get dialled. The weird thing is, if I change the last statement to this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:171"]];
the phone dials the number 171 without any issue
The solution to my particular problem is, as suggested below, to remove the spaces from the phone numbers. I achieved this as follows:
- (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]];
}
}