一、調用 自帶mail
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzlzh.com"]];web
二、調用 電話phone
三、調用 SMS
瀏覽器
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];函數
四、調用自帶 瀏覽器 safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];ui
調用phone能夠傳遞號碼,調用SMS 只能設定號碼,不能初始化SMS內容。代理
若須要傳遞內容能夠作以下操做:
加入:MessageUI.frameworkcode
#import <MessageUI/MFMessageComposeViewController.h>orm
實現代理:MFMessageComposeViewControllerDelegateip
-(IBAction)dialClicked:(id)sender { NSString *phoneNum = uil_phoneNumber.text;// 電話號碼 //第一種方法 直接撥打電話,不提示用戶,可是通話結束後會返回系統自帶的通信錄列表 if (phoneNum != nil && ![phoneNum isEqualToString:@""]) { NSString *telUrl = [NSString stringWithFormat:@"tel://%@",phoneNum]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]]; } // 第二種方法 在打電話前先提示用戶,通話結束後反饋開發者的應用程序 不合法,可能沒法經過蘋果商店的審覈。 if (phoneNum != nil && ![phoneNum isEqualToString:@""]) { NSString *telUrl = [NSString stringWithFormat:@"telprompt:%@",phoneNum]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]]; } // 第三種方法(效果和方法二同樣) 打電話前提示用戶,能返回開發者的應用程序 NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]]; if ( !phoneCallWebView && ![phoneNum isEqualToString:@""]) { phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];// 這個webView只是一個後臺的容易 不須要add到頁面上來 效果跟方法二同樣 可是這個方法是合法的 } [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]]; [self.view addSubview:phoneCallWebView]; }
調用sendSMS函數
//內容,收件人列表
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{ci
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];開發
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
// 處理髮送完的響應結果- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{ [self dismissModalViewControllerAnimated:YES]; if (result == MessageComposeResultCancelled) NSLog(@"Message cancelled") else if (result == MessageComposeResultSent) NSLog(@"Message sent") else NSLog(@"Message failed") }