-2

I want to create contacts app. How can I make a phone call with a button inside a custom UITableViewCell?

This is my code. It works only the first time when I press call button. When I NSLog it, it gives me a contact number. When I tap on the button, but don't show dialog box.

NSString *phoneStr = [[NSString alloc] initWithFormat:@"tel://%@",[contactNumbersArray objectAtIndex:indexPath.section]]; 

NSLog(@"%@", [contactNumbersArray objectAtIndex:indexPath.section]);

UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString: phoneStr] options:@{} completionHandler:nil];
Paulw11
  • 102,125
  • 14
  • 152
  • 166

2 Answers2

0

I solved it , as rmaddy said my numbers contain spaces and + so i solved it with this method

https://stackoverflow.com/a/27306065/9820328

-1

try using

  NSString *phNo = [contactNumbersArray objectAtIndex:indexPath.section];
  NSURL *phoneUrl = [NSURL URLWithString:[NSString  stringWithFormat:@"telprompt:%@",phNo]];

   if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
       UIApplication *application = [UIApplication sharedApplication];
       [application openURL:phoneUrl options:@{} completionHandler:nil];
   }
iOS Geek
  • 4,727
  • 1
  • 8
  • 29