Skip to content

iOS Make a call from String

Platform Language License

You can use a simple function below to make a call from your iOS app.

//MARK:- String
extension String {
    //MARK: makeACall
    func makeACall() {
        guard let url = URL(string: "tel://\(self)"), UIApplication.shared.canOpenURL(url) else { return }

        if #available(iOS 10, *) {
            UIApplication.shared.open(url)
        } else {
            UIApplication.shared.openURL(url)
        }
    }
}

You can call from anywhere like

"9876543210".makeACall()

"1(617)111-22-33".makeACall()

It will fail to run in some cases like below example

"#$%^:+1(617)111-22-33".makeACall()

"Phone: +1(617)111-22-33".makeACall()

Make sure that, your phone number should be in numeric format.

Note:

To get the result, run the app on a real device because it won't work on the simulator 

Let's grow together 🌱

Cheers 🍻