How to Make Phone Call in iOS

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

Given a phone number, how do I make a phone call in iOS?

Thanks to Leo Dabus,

I simply had to add the "tel://" aspect to each phone number. In this project, I decided to add this code snippet into my function rather than my CloudKit records.

if let call = detail.value(forKey: "Phone") as? String,
let url = URL(string: "tel://\(call)"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}

Calling a phone number in swift

Just try:

if let url = NSURL(string: "tel://\(busPhone)") where UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
}

assuming that the phone number is in busPhone.

NSURL's init(string:) returns an Optional, so by using if let we make sure that url is a NSURL (and not a NSURL? as returned by the init).


For Swift 3:

if let url = URL(string: "tel://\(busPhone)"), UIApplication.shared.canOpenURL(url) {
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}

We need to check whether we're on iOS 10 or later because:

'openURL' was deprecated in iOS 10.0

Making phone calls on the iPhone]

Try this:

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

... which will bring up a dialog in which your users will confirm the call.

How to make phone call with SwiftUI]

let numberString = "111-222-3334"

Button(action: {
let telephone = "tel://"
let formattedString = telephone + numberString
guard let url = URL(string: formattedString) else { return }
UIApplication.shared.open(url)
}) {
Text(numberString)
}

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.

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.



Related Topics



Leave a reply



Submit