几乎都是一样的想法,iOS中的所有应用程序都可以使用格式打开appShortName://whatyouwantToHandle
,对于网站来说它只是http://myurl
要拨打电话,它是tel
:
NSURL *phoneURL = [NSURL URLWithString:@"tel:+123456789"];
[[UIApplication sharedApplication] openURL:phoneURL];
要开始撰写电子邮件,它是mailto:
,并且它支持 GET 参数来填写电子邮件。
const NSString* mailFormat = @"mailto:%@?subject=%@&body=%@";
const NSString* mailEmails = @"person1@gmail.com,person2@gmail.com";
const NSString* mailBody = @"This is the mail body\n Hi!");
const NSString* mailSubject = @"This is the mail Subject!";
NSString *urlString = [NSString stringWithFormat:(NSString*)mailFormat,[mailEmails stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[mailSubject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[mailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *mailURL = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:mailURL];
正如你所期望的那样,打开网页,它只是http:
NSURL *websiteURL = [NSURL URLWithString:@"http://mywebsite.com"];
[[UIApplication sharedApplication] openURL:websiteURL];
-openURL:
如果您想了解更多信息,请查看文档。