How can I make phone call in iOS?

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


Solution 1:

You can initiate a call

https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

So this would probably work:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]  options:@{} completionHandler:nil];

Solution 2:

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];

Solution 3:

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.

Solution 4:

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..