How can I make phone call in iOS?

Viewed 57249

How can I make a phone call in Objective-C?

8 Answers

This is clipped from a project I did to do just that:

NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",phone_number];
NSURL *phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];

It may also be helpful to know how to prompt the user to call a number:

NSURL *phoneNumber = [NSURL URLWithString:@"telprompt://13232222222"];
[[UIApplication sharedApplication] openURL:phoneNumber];

telprompt gives the user a choice to place the call or cancel making the call before the phone dials. The two forward slashes after the colon are optional.

well if you are talking about using objective-c to make a phone call on the iphone, then you can do something like this:

NSURL *phoneNumber = [[NSURL alloc] initWithString: @"tel:867-5309"];
[[UIApplication sharedApplication] openURL: phoneNumber];

If you are talking about doing this on a mac ,well, then like others have mentioned that is specific based on number of things like, if you are using voip, a modem, connecting through something like an Asterisks box, etc..

This will either be very platform-specific, or you'll have to use a wrapper library to account for the differences among platforms, so you better state what platform this is intended for. In general, there are various telephony APIs available on most platforms.

On Windows systems there's for example the "TAPI", also things may somewhat differ if you are targeting a digital telephone system such as ISDN, because there are other APIs available.

Related