Call action implementation iOS swift || Call implementation || phone number call iOS swift || Phone call implementation when click the number iOS swift

Problem:

I want to create a button with title of phone number and if the user touches the button it wants to call that phone number.


Solution:

Just add the below code inside the action of that button and pass the number value.

Code:

 let cleanNumber = number.replacingOccurrences(of: "[^0-9+]", with: "", options: NSString.CompareOptions.regularExpression, range:nil);

            if let url = URL(string: "TEL://\(String(describing: cleanNumber))") {

                UIApplication.shared.open(url, options: [:], completionHandler: nil)

            }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift