[Xcode10 实际操作]八、网络与多线程-(3)使用UIApplication对象拨打电话

本文将演示如何使用应用程序单例对象,拨打电话的功能。

在项目导航区,打开视图控制器的代码文件【ViewController.swift】

注:需要使用真机进行测试。

 1 import UIKit
 2 
 3 class ViewController: UIViewController {
 4 
 5     override func viewDidLoad() {
 6         super.viewDidLoad()
 7         // Do any additional setup after loading the view, typically from a nib.
 8         
 9         //创建一个字符串,存储一个手机号码,
10         //并留意它的前缀格式【tel:】
11         let tel = "tel:18812345678"
12         //然后将字符串转换为网址对象
13         let url = URL(string:tel)
14         //获取应用程序单例对象,
15         //使用它打开网页的功能,
16         //调出通信面板
17         UIApplication.shared.openURL(url!)
18     }
19 
20     override func didReceiveMemoryWarning() {
21         super.didReceiveMemoryWarning()
22         // Dispose of any resources that can be recreated.
23     }
24 }

猜你喜欢

转载自www.cnblogs.com/strengthen/p/10054944.html