Dial a Phone Number with an Access Code Programmatically in iOS

Programmatically Dial a Phone number and pass DTMF using the iPhone SDK

The iPhone SDK does NOT give you direct access to dial numbers (imagine if a 'bad' program got on your phone and dialed a pay per minute number on mute so you didn't notice).

However, if you use the tel link, then you should be able to send it "," characters which inserts pauses.

So to dial 555-1212, then wait 4 seconds, then do 12345# on the touch tone you would use tel:5551212,,12345#

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

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)
}

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

iOS: Action Method to Dial Phone Number Upon User Tapping a Button

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

dial USSD code from iphone programmatically

You cannot dial a number containing * or # characters. Apple doesn't allow them in a dial string for security reasons.

Apple Documentation says :

To prevent users from maliciously redirecting phone calls or changing
the behavior of a phone or account, the Phone app supports most, but
not all, of the special characters in the tel scheme. Specifically, if
a URL contains the * or # characters, the Phone app does not attempt
to dial the corresponding phone number. If your app receives URL
strings from the user or an unknown source, you should also make sure
that any special characters that might not be appropriate in a URL are
escaped properly. For native apps, use the
stringByAddingPercentEscapesUsingEncoding: method of NSString to
escape characters, which returns a properly escaped version of your
original string.



Related Topics



Leave a reply



Submit