How to use openURL for making a phone call in Swift?

how to make a phone call in swift 4
swift 5 call phone number
swift call phone number
swift make phone call programmatically
this app is not allowed to query for scheme tel
swiftui call phone number
calling functionality in swift
call option in swift

I have converted the code for making a phone call from Objective-C to Swift, but in Objective-C, we can set the type of the URL that we like to open (e.g. telephone, SMS, web) like this:

@"tel:xx"
@"mailto:info@example.es"
@"http://stackoverflow.com"
@"sms:768number"

The code in Swift is:

UIApplication.sharedApplication().openURL(NSURL(string : "9809088798")

I read that have not released any scheme parameter for tel:, but I don't know if Swift can detect if the string is for making a phone call, sending email, or opening a website. Or may I write:

(string : "tel//:9809088798")

?

I am pretty sure you want:

UIApplication.sharedApplication().openURL(NSURL(string: "tel://9809088798")!)

(note that in your question text, you put tel//:, not tel://).

NSURL's string init expects a well-formed URL. It will not turn a bunch of numbers into a telephone number. You sometimes see phone-number detection in UIWebView, but that's being done at a higher level than NSURL.

EDIT: Added ! per comment below

How to use openURL for making a phone call in Swift , I have converted the code for making a phone call from Objective-C to Swift, but in Objective-C, we can set the type of the URL that we like to  I have converted the code for making a phone call from Objective-C to Swift, but in Objective-C, we can set the type of the URL that we like to open (e.g. telephone, SMS, web) like this:

A self-contained solution in Swift:

private func callNumber(phoneNumber:String) {
  if let phoneCallURL:NSURL = NSURL(string:"tel://\(phoneNumber)") {
    let application:UIApplication = UIApplication.sharedApplication()
    if (application.canOpenURL(phoneCallURL)) {
      application.openURL(phoneCallURL);
    }
  }
}

Now, you should be able to use callNumber("7178881234") to make a call.

How to make phone call in iOS 10 using Swift?, Step 4 − Create @IBAction method callButtonClicked for call button. Step 5 − To make a call we can use iOS openURL. In callButtonClicked  UIApplication.sharedApplication().openURL(NSURL(string : "9809088798") j'ai lu qui n'ont pas encore publié de régime paramètre tel: , mais je ne sais pas si Swift peut détecter si la chaîne est pour faire un appel téléphonique, envoyer un email, ou ouvrir un site web.

For Swift in iOS:

var url:NSURL? = NSURL(string: "tel://9809088798")
UIApplication.sharedApplication().openURL(url!)

Getting the best behavior from phone call requests using 'tel' in an , Using telprompt instead of tel in the openURL method will not only prompt the user if and how it compares to making phone calls via UIApplication. In iOS 8​, if I use the UIApplication call to open the URL, ending the call  Step 6 − Run the app and enter the number you want to make call to as shown in the pic below. Step 7 − Click on the call button, you will be shown an alert with ‘Call’ and ‘Cancel’ options. Step 8 − Click on the call button, the call will be made to the number, as shown below

You need to remember to remove the whitespaces or it won't work:

if let telephoneURL = NSURL(string: "telprompt://\(phoneNumber.stringByReplacingOccurrencesOfString(" ", withString: ""))") {
        UIApplication.sharedApplication().openURL(telelphoneURL)
    }

"telprompt://" will prompt the user to call or cancel while "tel://" will call directly.

Simple function to prompt a phone call on iOS in Swift · GitHub, Simple function to prompt a phone call on iOS in Swift openURL(phoneURL) pass the function in button, make an action connection from storyboard to view  swift phone call. nsurl – How to use openURL for making a phone call in Swift? – Stack Overflow. How to make phone calls in swift – Stack Overflow->

@ confile:

The problem is that your solution does not return to the app after the phone call has been finished on iOS7. – Jun 19 at 13:50

&@ Zorayr

Hm, curious if there is a solution that does do that.. might be a restriction on iOS.

use

UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://9809088798")!)

You will get a prompt to Call/Cancel but it returns to your application. AFAIK there is no way to return (without prompting)

Strategies for opening phone URLs in iOS apps, Something as simple as making a phone call or opening a URL on iOS having abused -[UIApplication canOpenURL:] to build and distribute  query phone open number not make for dialer calling app allowed ios swift swift3 ios10 phone-call How can I make a UITextField move up when the keyboard is present? How to trigger a phone call when clicking a link in a web page on mobile phone

Working with URL Schemes in iOS Apps, You can use a specific URL scheme to launch the built-in phone app and dial the number automatically. In this chapter, we'll make it even better. To open an application with a custom URL scheme, all you need to do is call the 1. UIApplication.shared.open(url, options: [:], completionHandler: nil)  For example, let’s say your app displays a phone number, and you want to make a call whenever a user taps that number. You can use a specific URL scheme to launch the built-in phone app and dial the number automatically. Similarly, you can use another URL scheme to launch the Message app for sending an SMS.

How To Make A Phone Call In Swift, How to make phone call button in iOS: Create a The next step is creating the new URL with the phone number and having your application open that URL. Apple introduced the openURL: method as a way to open external links with iOS 2. The related function canOpenURL: got some privacy controls in iOS 9 to stop you from querying devices for installed apps. Now with iOS 10 Apple has deprecated the plain old openURL for openURL:options:completionHandler:.

Use of Apple URL Schemes using Swift Language, I have converted the code for making a phone call from Objective-C to Swift, but in Objective-C, we can set the type of the URL that we like to  How to open a URL in Safari. Swift version: 5.1. Paul Hudson @twostraws June 1st 2019. If you want the user to exit your app and show a website in Safari, it's just

Comments
  • I don't see what the problem is. Did you try it? Did it work? And please do not delete and repost questions.
  • My problem is that I want know if this is correct for call: UIApplication.sharedApplication().openURL(NSURL(string : "9809088798") Because have only the emulator for try it
  • Just a tiny correction UIApplication.sharedApplication().openURL(NSURL(string: "tel://9809088798")!) you need to use the ! after the NSURL because it returns an optional.
  • this will directly start calling on the number (ofcourse after 10.3 iOS will ask permission to call) but what if I need to open the iPhone dialer with filled a number ?? Can I achieve this?
  • Awesome Answer sir :)
  • The problem is that your solution does not return to the app after the phone call has been finished on iOS7.
  • Hm, curious if there is a solution that does do that.. might be a restriction on iOS.
  • this will directly start calling on the number (ofcourse after 10.3 iOS will ask permission to call) but what if I need to open the iPhone dialer with filled a number ?? Can I achieve this?
  • This has already been posted many times. See wieblinger's answer, for example, or arshad's, etc. Please don't post duplicate content.