How can I dial a phone number that includes a number and access code programmatically in iOS?
For example:
number: 900-3440-567
Access C
UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:@"iPhone"] ) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:130-032-2837"]]];
} else {
UIAlertView *notPermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[notPermitted show];
[notPermitted release];
}
Using this user can redirect on Call and after the call he/she will automatically redirected to the app. It's working for me and sure about it.
if ([[device model] isEqualToString:@"iPhone"] ) {
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:cellNameStr];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} else {
UIAlertView *warning =[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warning show];
}
It's not possible to dial programmatically a phone number that includes number and access code.
The Apple Developer Library gives the following info:
"...the Phone application supports most, but not all, of the special characters in the tel scheme. Specifically, if a URL contains the * or # characters, the Phone application does not attempt to dial the corresponding phone number."
See: Apple URL Scheme Reference
Swift 5.0: In case someone needed an updated swift code:
private func callNumber(phoneNumber:String) {
if let phoneCallURL:NSURL = NSURL(string: "tel://\(phoneNumber)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(phoneCallURL as URL)
} else {
UIApplication.shared.openURL(phoneCallURL as URL)
}
}
}
}
You can programmatically dial phone numbers using UIApplication
's openURL:
method (see example below). I'm unsure if access codes are supported, but this is at least a starting point.
NSURL *URL = [NSURL URLWithString:@"tel://900-3440-567"];
[[UIApplication sharedApplication] openURL:URL];
Edit: See the Apple URL Scheme Reference and the UIApplication Class Reference for more information.
follow the tutorial
http://www.makebetterthings.com/blogs/iphone/open-phone-sms-email-map-and-browser-apps-in-iphone-sdk/
to call a number use -
NSURL *url = [NSURL URLWithString:@"tel://012-4325-234"];
[[UIApplication sharedApplication] openURL:url];
to open your app after call finished use -
(Note: telprompt is undocumented)
NSURL *url = [NSURL URLWithString:@"telprompt://012-4325-234"];
[[UIApplication sharedApplication] openURL:url];