一.打电话
//打电话
//弊端:使用该方法进行拨号之后,当电话挂断之后不会返回应用程序,会停留在通话记录界面
NSURL *url=[NSURLURLWithString:@"tel://10010"];
[[UIApplicationsharedApplication] openURL:url];
NSLog(@"tel://10010");
//在拨打之后会提示用户是否拨打,当电话挂断之后会返回应用程序
//弊端:因为是私有API,所有可能不会被审核通过
NSURL *url1=[NSURLURLWithString:@"telprompt://10010"];
[[UIApplicationsharedApplication] openURL:url1];
//真实开发用此种方式
if (_webView==nil) {
_webView = [[UIWebViewalloc] initWithFrame:CGRectZero];
}
[_webViewloadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:@"tel://10010"]] ];
二.发短信
//如果利用该方式发送短信,当短信发送完毕或取消之后不会返回应用程序
NSURL *url = [NSURLURLWithString:@"sms://10010"];
[[UIApplication sharedApplication] openURL:url];
//导入MessageUI框架,用此种方式发送短信
if (![MFMessageComposeViewControllercanSendText]) {
NSLog(@"该设备不能发送短信");
return ;
}
//发短信
MFMessageComposeViewController *vc=[[MFMessageComposeViewControlleralloc] init];
//设置短信内容
vc.body=@"短信内容";
//设置收件人列表
vc.recipients=@[@"10010",@"02010010"];
//设置代理
vc.messageComposeDelegate=self;
//显示控制器
[selfpresentViewController:vc animated:YEScompletion:nil];
//判断短信发送状态,取消发送短信模态视图
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
//取消发短信模态视图
[controller dismissViewControllerAnimated:YEScompletion:nil];
if (MessageComposeResultCancelled==result) {
NSLog(@"取消发送");
}
elseif(MessageComposeResultSent==result)
{
NSLog(@"发送成功");
}
else
{
NSLog(@"发送失败");
}
}
三.发送邮件
if (![MFMailComposeViewControllercanSendMail]) {
return ;
}
//发送邮件
MFMailComposeViewController *vc=[[MFMailComposeViewControlleralloc] init];
//设置邮件主题
[vcsetSubject:@"会议"];
//设置邮件内容
[vc setMessageBody:@"今天下午开会“"isHTML:NO];
//设置收件人列表
[vc setToRecipients:@[@"1198071487@qq.com"]];
//设置抄送人列表
[vc setCcRecipients:@[@"1198071487@qq.com"]];
//设置密送人列表
[vc setBccRecipients:@[@"563154033@qq.com"]];
//添加附件(一张图片)
UIImage *image=[UIImageimageNamed:@"picture.jepg"];
NSData *data =UIImageJPEGRepresentation(image,0.5);
[vc addAttachmentData:datamimeType:@"image/jepg"fileName:@"picture.jepg"];
//设置代理
vc.mailComposeDelegate=self;
//显示控制器,以模态方式打开
[selfpresentViewController:vc animated:YEScompletion:nil];
#pragma mark -MFMailComposeViewControllerDelegate
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
//关闭邮件界面
[controller dismissViewControllerAnimated:YEScompletion:nil];
if (MFMailComposeResultCancelled==result) {
NSLog(@"取消发送");
}
elseif(MFMailComposeResultSent==result)
{
NSLog(@"发送成功");
}
elseif (MFMailComposeResultSaved==result)
{
NSLog(@"保存成功");
}
else
{
NSLog(@"发送失败");
}
}