6

How to make a Phone Call in SwiftUI. Here is the sample code with Swift and UIKit:

guard let number = URL(string: "tel://" + "+1(222)333-44-55") else { return }
UIApplication.shared.open(number)

Here is the thread for Swift and the UIKit Version:

How to make phone call in iOS 10 using Swift?

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
Jonas Deichelmann
  • 3,513
  • 1
  • 30
  • 45
  • 1
    Does this answer your question? [How to create tappable url/phone number in SwiftUI](https://stackoverflow.com/questions/57582653/how-to-create-tappable-url-phone-number-in-swiftui) – chirag90 Feb 25 '20 at 15:40

1 Answers1

6
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)
}
Jonas Deichelmann
  • 3,513
  • 1
  • 30
  • 45
Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
  • I wonder how this compares to using `URLComponents`, and setting the scheme to `"tel"`. It abstracts away the `://` so it feels more "proper", but I'm not sure if it's preferable – Alexander Feb 25 '20 at 15:55