1. 程式人生 > >[Xcode10 實際操作]八、網路與多執行緒-(4)使用UIApplication物件傳送簡訊

[Xcode10 實際操作]八、網路與多執行緒-(4)使用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 //並留意它的字首格式【sms:】 11 let tel = "sms: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 }