Making a Phone Call in an iOS Application

Making a phone call in an iOS application

Yup. You need to take those out yourself. Or you can use the snippet below...

NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", cleanedString]];

Note: you may be tempted to use -stringByTrimmingCharactersInSet:, but that one only removes characters at the start and the end of the string, not if they appear in the middle.

iOS making a phone call from the app without a confirmation alert

Unfortunately, what you desire to do is not possible, at least in the existing versions of iOS. That dialog will always show.

Per Apple's documentation for openURL:

When a third party application invokes openURL: on a tel://,
facetime://, or facetime-audio:// URL, iOS displays a prompt and
requires user confirmation before dialing.

Make a phone call programmatically

Probably the mymobileNO.titleLabel.text value doesn't include the scheme //

Your code should look like this:

ObjectiveC

NSString *phoneNumber = [@"tel://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

Swift

if let url = URL(string: "tel://\(mymobileNO.titleLabel.text))") {
UIApplication.shared.open(url)
}

How can I make phone call in iOS?

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

Make phonecall through application

It is possible to make phone calls through an application (you'd have to design your own UI because there aren't any iOS UI elements for it). I've seen phone calling apps (just a quick Google search turns up a few).

Your question isn't clear about whether it is an automated call or not, if so: According to the iOS Human Interface Guidelines, your application should not place calls, send messages or e-mails without the users direct consent. You may also want to review the AppStore guidelines to see if your app idea complies. if you app places automated calls or sends automated messages, it will be rejected / removed from the AppStore.

If the call is not automated, you can initiate a call using this code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:13214567890"]];

This code opens the phone app. There is currently no way to stay in your app for a phone call, and then terminate it within your own app - that is all handled by the phone app. It should also be noted that this code will not work in the iOS Simulator because the simulator has no phone app.

Refer here for the full documentation from Apple. You may also want to check out these other StackOverflow Posts:

  • Make phone call on iPhone and take user back to app? (UIWebView does it)
  • Dial a phone number with an access code programmatically


Related Topics



Leave a reply



Submit