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
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.
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 } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With