How to make a phone call through programming

How to make a phone call through programming in iOS?

+3
source share
4 answers

Use the UIApplication: openURL method to open a resource from another program. This includes opening mail, phone numbers, searching for Google maps, etc.

So, so that you can call someone using the method, you can use

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:123456789"]];
+3
source

I think you can use the tel: // URL to indicate the phone number in the same way you would specify a web page with http: //

This simplifies the transition from a web interface to a voice style phone interface. The format also theoretically supports alternative SIP providers and extensions.

+2

You can use this code for calls.

extension String {
func callOn() {
    if let numberURL = URL(string: "tel://\(self)") {
        guard (UIApplication.shared.canOpenURL(numberURL)) else { return }
        UIApplication.shared.open(numberURL, options: [:], completionHandler: nil)
    }
  }
}

Just call the method with the contact number

"0123456789".callOn()
-1
source

Source: https://habr.com/ru/post/1710325/


All Articles