Apple URL 方案
這些是 iOS,OS X 和 watchOS 2 及更高版本上的本機應用程式支援的 URL 方案。
在 Safari 中開啟連結:
Objective-C 的
NSString *stringURL = @"http://stackoverflow.com/";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
迅速:
let stringURL = "http://stackoverflow.com/"
if let url = URL(string: stringURL) {
UIApplication.shared.openURL(url)
}
開始電話交談
Objective-C 的
NSString *stringURL = @"tel:1-408-555-5555";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
迅速:
let stringURL = "tel:1-408-555-5555"
if let url = URL(string: stringURL) {
UIApplication.shared.openURL(url)
}
HTML
<a href="tel:1-408-555-5555">1-408-555-5555</a>
開始 FaceTime 對話
Objective-C 的
NSString *stringURL = @"facetime:14085551234";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
迅速:
let stringURL = "facetime:14085551234"
if let url = URL(string: stringURL) {
UIApplication.shared.openURL(url)
}
HTML
<a href="facetime:14085551234">Connect using FaceTime</a>
<a href="facetime:user@example.com">Connect using FaceTime</a>
開啟訊息應用程式以將簡訊撰寫為收件人:
Objective-C 的
NSString *stringURL = @"sms:1-408-555-1212";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
迅速:
let stringURL = "sms:1-408-555-1212"
if let url = URL(string: stringURL) {
UIApplication.shared.openURL(url)
}
HTML
<a href="sms:">Launch Messages App</a>
<a href="sms:1-408-555-1212">New SMS Message</a>
開啟郵件應用以撰寫傳送給收件人的電子郵件:
Objective-C 的
NSString *stringURL = @"mailto:foo@example.com";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
迅速:
let stringURL = "mailto:foo@example.com"
if let url = URL(string: stringURL) {
UIApplication.shared.openURL(url)
}
HTML
<a href="mailto:frank@wwdcdemo.example.com">John Frank</a>
你還可以在收件人,抄送和密件抄送欄位中包含主題欄位,郵件和多個收件人。 (在 iOS 中,將忽略 from 屬性。)以下示例顯示包含多個不同屬性的 mailto URL:
mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!
注意: Compose 電子郵件對話方塊也可以使用 MFMailComposeViewController
在 app 中顯示。