J'ai une tableView qui a des cellules avec des numéros de téléphone. L'application ne compose pas les chiffres si. Voir le code ci-dessousPourquoi mes liens "tel:" ne fonctionnent-ils pas?
- (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
Comme vous pouvez le voir, le nombre va à la console, mais ne sont pas composé.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:171"]];
le téléphone compose le numéro 171 sans aucun problème
La solution à mon problème particulier est, comme suggéré ci-dessous, à: si je change la dernière déclaration à cette chose étrange est, supprimer les espaces des numéros de téléphone. J'ai réalisé ceci comme suit:
- (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]];
}
}