Krish Mehra Krish Mehra - 5 months ago 44
iOS Question

How do I open this URL to make a phone call in swift?

When I tried to open let url in swift using UIApplication.shared.openURL(url!), it would call the right number but it would add weird digits before it. For example if I type 2345678901 as a number it'll show weird digits ( What should I do to open the let url? Here is the code:

import UIKit

class ViewController: UIViewController {
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.

@IBOutlet weak var myText: UITextField!
override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated.

@IBAction func btn(_ sender: AnyObject) {
var numbers = self.myText.text

let comp = NSURLComponents()
comp.scheme = "tel" = "\(numbers)"
let url = comp.url



You are using swift 3.0 so use open because openUrl is deprecated.

if let url = URL(string: "tel://\(number)") {, options: [:])