0

Possible Duplicate:
How to make a call programmatically?

In my App, I have one view in which complete address along with phone number of a company gets displayed. What i want is, when a user touches that phone number, it should make a call.. So, how to do it, when user touches that phone number. Any answer will be appriciated. Thank you guys.

Community
  • 1
  • 1
Tarunkumar
  • 11
  • 1
  • 3
  • 1
    try this ... [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:91-775-107-1248"]]; – Dhiru Nov 09 '16 at 11:20

4 Answers4

0

If you put the text in a UITextView there is a setting for it to automatically detect phone numbers. The OS will then highlight the phone number, and if the user taps on it, it will prompt them if they wish to call that number

Dan F
  • 17,654
  • 5
  • 72
  • 110
0
-(IBAction)callPhone:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:1234567890"]];
}

Then connect TouchUpInside to this and you are good to go. Hope that helps!

Blueberry
  • 2,211
  • 3
  • 19
  • 33
0
-(void)callPhone:(id)sender{

    NSURL *url = [NSURL URLWithString: @"tel://848444488"];
    NSLog(@"Call %@", url);
    [[UIApplication sharedApplication] openURL:url];

}

if the phone is in the form 848 44 44 88 use this code to eliminate spaces:

NSString *phoneWithoutSpaces = [[NSString stringWithFormat:@"tel://%@", @"848 44 44 88"] stringByReplacingOccurrencesOfString:@" " withString:@""];

NSURL *url = [NSURL URLWithString:phoneWithoutSpaces];
Alexey
  • 7,127
  • 9
  • 57
  • 94
0

Do this

NSString *phoneNumber = [NSString StringWithFormat:@"tel:%@", textField.text];

[[UIApplication SharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Justin Paulson
  • 4,388
  • 1
  • 23
  • 28