Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a phone number from ios app? [duplicate]

I'm trying to call a phone number from ios app using: It's not working, although the method gets called:

-(IBAction)callPhone:(id)sender {          NSString *phoneCallNum = [NSString stringWithFormat:@"tel://%@",listingPhoneNumber ];          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneCallNum]];          NSLog(@"phone btn touch %@", phoneCallNum);     } 

NSLog output: phone btn touch tel://+39 0668806972

like image 396
user2588945 Avatar asked Sep 20 '13 10:09

user2588945


People also ask

Why are phone numbers duplicated on iPhone?

Duplicate contacts on your iPhone can occur as the result of using iCloud, or due to an issue with your address book or email client on your computer. When using your iPhone for both your business and personal purposes, you may create duplicate contacts by syncing with more than one service.


1 Answers

your code is correct. did you check in real device. this function will not work in simulator.

try this also,

NSString *phNo = @"+919876543210"; NSURL *phoneUrl = [NSURL URLWithString:[NSString  stringWithFormat:@"telprompt:%@",phNo]];      if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {         [[UIApplication sharedApplication] openURL:phoneUrl];     } else     {         calert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Call facility is not available!!!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];         [calert show];     } 

** Swift 3 version**

if let url = URL(string: "telprompt:\(phoneNumber)") {   if UIApplication.shared.canOpenURL(url) {     UIApplication.shared.open(call, options: []) { result in        // do something with result     }   } } 
like image 159
Yas Avatar answered Sep 23 '22 14:09

Yas