In my app I want to call to selected number. For this I have following code
+(void)makeCallToSelectedContact:(NSString*)phoneNo{
NSMutableString *phoneNumber = [NSMutableString stringWithString:phoneNo];
[phoneNumber replaceOccurrencesOfString:@" "
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [phoneNumber length])];
[phoneNumber replaceOccurrencesOfString:@"("
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [phoneNumber length])];
[phoneNumber replaceOccurrencesOfString:@")"
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [phoneNumber length])];
NSLog(@"phoneNumber => %@",phoneNumber);
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]];
}
else {
NSLog(@"Unable to open");
[self showAlertWithTitle:@"Alert" andMessage:@"This Device Doesn't Support Call Functionality"];
}
}
Lets say if I have ph no like +91 1234567890 , then it will call the number correctly. But if I have number without + & country code like 1234567890 then it is converting it to +12 34567890 which is wrong phone number. Here is my console log
2012-04-05 19:13:37.960 Search[22453:11003] phoneNumber => +911234567890
2012-04-05 19:13:47.928 Search[22453:11003] phoneNumber => 1234567890
What I am missing ? Any kind of help is appreciated.
You are adding the '+' when you create the URL - Look :
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]];
}