I checked and tried previous answers on how to make call directly from the app but I keep getting errors. I just made a button in the storryboard and hooked it up to the view controller. It keeps giving me the ERROR Excpected ',' separator but that doesn't solve anything. Do I need to add code to the AppDelegate or anything else? I really would like to know the way to do this in Swift.
import UIKit
class ViewController: UIViewController {
@IBAction func theCallMeButtonMethod(sender: AnyObject) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:0123456789"]]
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Swift 3
This code will help you :
let phone = "tel://982374234"
let url = URL(string: phone)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
OR
let url = URL(string: "tel://9809088798")!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
This is how you access the application object and open a URL in swift.
Replace number below:
UIApplication.sharedApplication().openURL(NSURL(string:"telprompt:0123456789"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With