我检查并尝试过以前的答案,如何直接从应用程序拨打电话,但我不断收到错误.我刚刚在储物柜中制作了一个按钮,并将其连接到视图控制器.它不断给我“错误审查”,“分隔符,但这并不解决任何事情.我需要向AppDelegate或其他任何内容添加代码吗?我真的想知道在斯威夫特这样做的方式.
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. } }
解决方法
此代码将帮助您:
let phone = "tel://982374234"; let url:NSURL = NSURL(string:phone); UIApplication.sharedApplication().openURL(url);
要么
var url:NSURL = NSURL(string: "tel://9809088798") UIApplication.sharedApplication().openURL(url)