Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone call from app in Swift Xcode 6 [closed]

Tags:

ios

swift

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.
    }


}
like image 516
YannisDC Avatar asked Aug 04 '14 11:08

YannisDC


2 Answers

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)
   
like image 73
Rijo Payyappilly Avatar answered Sep 20 '22 23:09

Rijo Payyappilly


This is how you access the application object and open a URL in swift.

Replace number below:

UIApplication.sharedApplication().openURL(NSURL(string:"telprompt:0123456789"))
like image 28
Lev Landau Avatar answered Sep 20 '22 23:09

Lev Landau