发短信/邮件/打电话
2016-04-22 09:30
417 查看
1.发短信
1.1简单方式
不能指定发短信的内容
不能回到原来的应用
1.2
2.发邮件
3.打电话
//直接呼叫
- (void)tela {
NSURL *url = [NSURL URLWithString:@"tel://18602534746"];
[[UIApplication sharedApplication] openURL:url];
}
//会有提示,取消或呼叫;上线可能被拒绝
- (void)telb {
NSURL *url = [NSURL URLWithString:@"telprompt://18602534746"];
[[UIApplication sharedApplication] openURL:url];
}
//有提示,不被拒绝
- (void)telc {
NSURL *url = [NSURL URLWithString:@"tel://18602534746"];
if (_webView == nil) {
_webView = [[UIWebView alloc]initWithFrame:CGRectZero];
}
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}
1.1简单方式
不能指定发短信的内容
不能回到原来的应用
<span style="font-size:18px;">
- (IBAction)sendMsg:(id)sender { NSURL *url = [NSURL URLWithString:@"sms://1860253****"]; [[UIApplication sharedApplication] openURL:url]; }
</span>
1.2
<span style="font-size:18px;">
#import <MessageUI/MessageUI.h> - (void)sendMsgToPhones:(NSArray *)phones title:(NSString *)title body:(NSString *)body { //判断设备是否支持发短信 if ([MFMessageComposeViewController canSendText]) { //创建发短信的控制器 MFMessageComposeViewController *msgController = [MFMessageComposeViewController new]; //接收者 msgController.recipients = phones; msgController.title = title; msgController.body = body; //代理 msgController.messageComposeDelegate = self; msgController.navigationBar.tintColor = [UIColor redColor]; [self presentViewController:msgController animated:YES completion:nil]; } else { NSLog(@"这个设备不支持发短信"); } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultCancelled: NSLog(@"取消"); break; case MessageComposeResultSent: NSLog(@"成功"); break; case MessageComposeResultFailed: NSLog(@"失败"); break; default: break; } } - (IBAction)sendMsg:(id)sender { [self sendMsgToPhones:@[@"186025*****"] title:@"新短信" body:@"测试发短信"]; }
</span>
2.发邮件
<span style="font-size:18px;">
- (IBAction)sendMail:(id)sender { if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailController = [MFMailComposeViewController new]; [mailController setSubject:@"我的邮件"]; [mailController setToRecipients:@[@"862071994@qq.com"]]; //抄送 //mailController setCcRecipients: //密送 //mailController setBccRecipients: [mailController setMessageBody:@"这是我的周报<font color=\"blue\" size =15 > 周报的内容 </font> 请审阅" isHTML:YES]; //附件 UIImage *image = [UIImage imageNamed:@"u=1713462169,1947795988&fm=15&gp=0"]; NSData *data = UIImagePNGRepresentation(image); [mailController addAttachmentData:data mimeType:@"image/png" fileName:@"abc.png"]; mailController.mailComposeDelegate = self; [self presentViewController:mailController animated:YES completion:nil]; } else { NSLog(@"这个设备不支持发邮件"); } } - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MFMailComposeResultCancelled: NSLog(@"取消"); break; case MFMailComposeResultFailed: NSLog(@"失败"); break; case MFMailComposeResultSaved: NSLog(@"保存"); break; case MFMailComposeResultSent: NSLog(@"成功"); break; default: break; } }
</span>
3.打电话
//直接呼叫
- (void)tela {
NSURL *url = [NSURL URLWithString:@"tel://18602534746"];
[[UIApplication sharedApplication] openURL:url];
}
//会有提示,取消或呼叫;上线可能被拒绝
- (void)telb {
NSURL *url = [NSURL URLWithString:@"telprompt://18602534746"];
[[UIApplication sharedApplication] openURL:url];
}
//有提示,不被拒绝
- (void)telc {
NSURL *url = [NSURL URLWithString:@"tel://18602534746"];
if (_webView == nil) {
_webView = [[UIWebView alloc]initWithFrame:CGRectZero];
}
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}
相关文章推荐
- 十个值得研究的C开源项目!
- HDU 1021 Fibonacci Again
- java程序中对堆栈的理解
- java基础(12)-- 深入理解Collections.sort()
- tomcat监听器ServletContextListener加载web应用数据
- 正则表达 基础学习
- 2016.04.22,英语,《Vocabulary Builder》Unit 17
- MySQL安装过程net start mysql 启动失败 报“错误2,系统找不到文件”的解决办法
- 你不知道的对称密钥与非对称密钥
- JS中数组去除重复
- C#模拟http 发送post请求 模拟登录
- 新建maven时报错-----------解决:换一个工作空间,或者将工作空间的pom.xm删除
- Hibernate 单向多对一&单向一对多&单向多对多
- android 布局属性大全
- 1031. Hello World for U (20)
- MATLAB im2colstep
- OpenKM开发环境搭建
- 一个类似MIUI中原生短信编辑功能
- MVC 自定义IModelBinder实现json参数转Dictionary<string, string>
- 青云 ubuntu下mysql远程连接配置