'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead
最新的iOS版本中没有 UIApplication.shared.openURL(url)
let website = "https://www.jianshu.com/p/a2492b3fd9a4"
//创建一个字符串转换为网址对象
let url = URL(string: website)!
UIApplication.shared.openURL(url)
拨打电话,需要真机调试
let tel = "tel:15933850872"
//注意格式
let url1 = URL(string: tel)!
UIApplication.shared.openURL(url1)
发送短信,自动打开发送界面
let tel = "sms:15933850872"
let url = URL(string: tel)!
UIApplication.shared.openURL(url)
发送邮件
let tel = "mailto:1312765298@qq.com"
let url = URL(string: tel)!
UIApplication.shared.openURL(url)
掉用地址网页
func openMap() {
//创建一个方法,实现打开地图的方法。
var address = "Beijing"
//对字符串进行编码,使地图能够解析到正确的地理位置。。
address = address.addingPercentEncoding(withAllowedCharacters: CharacterSet())!
//创建一个字符串常量,掉用百度d地图的相关接口
let urlText = "https://maps.baidu.cn/maps?q=\(address)"
//转换字符串为网站对象
let url = URL(string: urlText)!
//获得应用程序的单例对象,然后调用对象的打开网站方法,打开指定路径的网址.
UIApplication.shared.openURL(url)
先对字符串进行编码,然后解析到正缺的地理位
let urlText = "https://maps.baidu.cn/maps?q=\(address)"
//转换字符串为网站对象
最后调用程序的单利对象,打开指定路径的网址
let url = URL(string: urlText)!
//获得应用程序的单例对象,然后调用对象的打开网站方法,打开指定路径的网址.
UIApplication.shared.openURL(url)