1. 程式人生 > >[Xcode10 實際操作]八、網絡與多線程-(5)使用UIApplication對象發送郵件

[Xcode10 實際操作]八、網絡與多線程-(5)使用UIApplication對象發送郵件

tro 導航 ide 網絡 文件 項目 nbsp ica UNC

本文將演示如何使用應用程序單例對象,發送郵件的功能。

在項目導航區,打開視圖控制器的代碼文件【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 //並留意它的前綴格式【mailto:】 11 let tel = "mailto:[email protected]" 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 }

[Xcode10 實際操作]八、網絡與多線程-(5)使用UIApplication對象發送郵件