[Xcode 实际操做]8、网络与多线程-(5)使用UIApplication对象发送邮件

目录:[Swift]Xcode实际操做html

本文将演示如何使用应用程序单例对象,发送邮件的功能。swift

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

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

 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:newsagency@163.com"
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 }
相关文章
相关标签/搜索