NSURL *url= [NSURL URLWithString:@”http://www.baidu.com"];
[[UIApplication sharedApplication] openURL:url];
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
@interface ViewController ()<MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//----------------------------打电话的三种方式
//方式1, 通话结束时回到通讯录里。不会回到应用程序
NSURL *url=[NSURL URLWithString:@"tel://10086"];
[[UIApplication sharedApplication]openURL:url];
//方式2,(弹出提示框)通话结束自动回到原来的应用程序,用的是私有api,不能上传上苹果商店,适合做越狱的。
NSURL *url1=[NSURL URLWithString:@"telprompt://10086"];
[[UIApplication sharedApplication]openURL:url1];
//方式3,(弹出提示框)通话结束看自动回到原来的应用程序 这个比较合理
UIWebView *web=[[UIWebView alloc]init];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10086"]]];
//不需要添加到视图上, 不然会挡住其它界面
//[self.view addSubview:web];
//----------------------------发短信的二种方式
//方式1 直接跳到短信界面,不能指定短信内容,不能回到原应用程序
NSURL *url2=[NSURL URLWithString:@"sms://10086"];
[[UIApplication sharedApplication]openURL:url2];
//方式2
/* 1,需要添加 MessageUI.framework 框架
*/
//创建短信控制器
MFMessageComposeViewController *vc=[[MFMessageComposeViewController alloc]init];
//设置短信内容
vc.body=@"短信内容";
//设置收件人
vc.recipients=[NSArray arrayWithObjects:@"10086",@"10010", nil];
//设置代理
vc.messageComposeDelegate=self;
//显示控制器
[self presentViewController:vc animated:YES completion:nil];
//----------------------------发邮件的二种方式
//方法一 系统自带的邮件客户端, 不能加到原应用程序
NSURL *url3=[NSURL URLWithString:@"mailto://551730360@qq.com"];
[[UIApplication sharedApplication]openURL:url3];
//方法二 和发短信一样,用的的框架
//创建发邮件的控制器
MFMailComposeViewController *mailvc=[[MFMailComposeViewController alloc]init];
mailvc.mailComposeDelegate=self;
//设置主题
[mailvc setSubject:@"大家好"];
//设置邮件内容
[mailvc setMessageBody:@"<font color=\"red\">哈哈</fon>" isHTML:YES];
//设置发送人
[mailvc setToRecipients:[NSArray arrayWithObjects:@"551730360",@"12306.qq.com", nil]];
//设置抄送
[mailvc setCcRecipients:[NSArray arrayWithObjects:@".--.qcom", nil]];
//设置密送
[mailvc setBccRecipients:[NSArray arrayWithObjects:@"ddff.com", nil]];
//添加附件
NSURL *url4=[[NSBundle mainBundle]URLForResource:@"图片名" withExtension:@"png"];
NSData *data=[NSData dataWithContentsOfURL:url4];
[mailvc addAttachmentData:data mimeType:@"image/png" fileName:@"图片名.png"];
[self presentViewController:mailvc animated:YES completion:nil];
}
#pragma mark -代理方法,短信界面关闭结束的时候调用。
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
/*
result 的三个状态
MessageComposeResultCancelled, 取消的 0
MessageComposeResultSent, // 成功 1
MessageComposeResultFailed// 失败 2
*/
//关闭短信界面
[controller dismissViewControllerAnimated:YES completion:nil];
if (result==MessageComposeResultCancelled)
{
NSLog(@"取消发送");
}
else if (result==MessageComposeResultSent)
{
NSLog(@"发送成功");
}
else if (result==MessageComposeResultFailed)
{
NSLog(@"发送失败");
}
}
#pragma mark - 发邮件结束时调用
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
/*
result 的四个状态
MFMailComposeResultCancelled,取消的 0
MFMailComposeResultSaved, 是否存草搞 1
MFMailComposeResultSent, 成功 2
MFMailComposeResultFailed 失败 3
*/
if (result==MFMailComposeResultCancelled)
{
NSLog(@"取消发送");
}
else if (result==MFMailComposeResultSaved)
{
NSLog(@"是否存草搞");
}
else if (result==MFMailComposeResultSent)
{
NSLog(@"发送成功");
}
else if (result==MessageComposeResultFailed)
{
NSLog(@"发送失败");
}
//关闭邮箱界面
[controller dismissViewControllerAnimated:YES completion:nil];
}