#import "ViewController.h"
#import <MessageUI/MessageUI.h> //导入信息UI库 @interface ViewController () <MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate> @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (IBAction)callPhone:(id)sender {
//方式1 :拼接字符串 注意开头是tel: 这种方式打电话回不到原来应用中,会停留在通讯录里,而且是直接拨打电话 没有任何弹窗提示
// NSString *str = [NSString stringWithFormat:@"tel:%@",self.phoneTextField.text];
// //首先得到应用的单例对象 然后调用openURL:这个方法 参数是url对象
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; //方式2,这种方式有弹窗提示,并且能回到原来应用中 推荐这种
// NSString *str1 = [[NSString alloc] initWithFormat:@"tel:%@",self.phoneTextField.text];
// //创建UIWebView对象
// UIWebView *callWebView = [[UIWebView alloc] init];
// //加载一个请求对象 这个请求对象通过url对象创建 url对象又通过str1字符串获得
// [callWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str1]]];
// //加入到self.view上
// [self.view addSubview:callWebView]; //方式3
//这种方式 也可以有弹窗提示 并且也能回到原来的应用中 也推荐这种
NSString *str2 = [NSString stringWithFormat:@"telprompt:%@",self.phoneTextField.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str2]]; } - (IBAction)callWeb:(id)sender { //打开网址 注意:打开的网址注意是http:// 或是https://
NSString *str = [NSString stringWithFormat:@"https://%@",self.webTextField.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; }
- (IBAction)sendSMS:(id)sender { //方式1:这种方式没法回到应用中,但是注意不要写中文等特殊字符 否则无法跳到发短信界面
//优点:简单 缺点:不能指定发送内容,只能指定发送人,而且不能回到应用中
// NSString *str = [NSString stringWithFormat:@"sms://%@",self.smsTextField.text];
// NSURL *url = [NSURL URLWithString:str];
// [[UIApplication sharedApplication] openURL:url]; //方式2 推荐这种
/*
优点:1.从应用出来并且能回到应用中
2.可以发送多人
3.可以用代码自定义消息
4.如果手机开通了iMessage功能,会走网络通道,不走运营商通道
*/ //判断用户设备是否能发送短信
if (![MFMessageComposeViewController canSendText]) {
NSLog(@"不能发送内容"); return ;
} //1.创建一个短信控制器对象
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; //2.设置短信内容
// (1)收件人
controller.recipients = @[@"",@""];
// (2)短信内容
controller.body = @"你好啊 你俩";
// (3)设置短信代理
controller.messageComposeDelegate = self; //3.显示短信控制器 [self presentViewController:controller animated:YES completion:^{
NSLog(@"显示短信控制器完成代码块");
}]; } #pragma mark - 短信控制器代理方法 - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { /*
MessageComposeResultCancelled, 取消
MessageComposeResultSent, 发送
MessageComposeResultFailed 失败 result枚举
*/
NSLog(@"%d",result); //注:别忘了回到应用中
[controller dismissViewControllerAnimated:YES completion:^{
NSLog(@"短信控制器消失完成后代码块");
}]; } - (IBAction)sendEmail:(id)sender { //方式1
// NSString *str = [NSString stringWithFormat:@"mailto://%@",self.emailTextField.text];
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; //方式2
//判断是否能发送邮件
if (![MFMailComposeViewController canSendMail]) {
NSLog(@"不能发送邮件");
return;
}
//创建mail控制器对象
MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
//设置邮件主题
[vc setSubject:@"我爱你"];
//设置邮件发送内容 第二个参数支持HTML格式
[vc setMessageBody:@"基本的电话、邮件、短信" isHTML:YES];
//设置收件人列表
[vc setToRecipients:@[@"*******@qq.com"]];
//设置抄送人列表
[vc setCcRecipients:@[@"********@qq.com",@"********@163.com"]];
//设置邮件代理
vc.mailComposeDelegate = self;
//显示邮件控制器
[self presentViewController:vc animated:YES completion:^{
NSLog(@"跳转完成后执行代码块");
}]; } - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { /*
result枚举类型
MFMailComposeResultCancelled, 取消
MFMailComposeResultSaved, 保存
MFMailComposeResultSent, 发送
MFMailComposeResultFailed 失败
*/
NSLog(@"%d",result); [controller dismissViewControllerAnimated:YES completion:^{
NSLog(@"邮箱控制器消失完成后代码块");
}]; }
@end

打电话、发短信、web以及发邮件

另外补充一下,用下面的个人感觉更好一些!上面的UIWebView好像弹框的速度有点慢 自己弹框一下更方便一些

- (void)callAction:(NSString *)phone{

NSMutableString* str1=[[NSMutableString alloc]initWithString:phone];//存在堆区,可变字符串

[str1 insertString:@"-"atIndex:3];//把一个字符串插入另一个字符串中的某一个位置

[str1 insertString:@"-"atIndex:8];//把一个字符串插入另一个字符串中的某一个位置

UIAlertController *alert = [UIAlertController alertControllerWithTitle:str1 message:nil preferredStyle:UIAlertControllerStyleAlert];

// 设置popover指向的item

alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;

// 添加按钮

[alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {

NSLog(@"点击了呼叫按钮");

NSString* phoneStr = [NSString stringWithFormat:@"tel://%@",phone];

if ([phoneStr hasPrefix:@"sms:"] || [phoneStr hasPrefix:@"tel:"]) {

UIApplication * app = [UIApplication sharedApplication];

if ([app canOpenURL:[NSURL URLWithString:phoneStr]]) {

[app openURL:[NSURL URLWithString:phoneStr]];

}

}

}]];

[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

NSLog(@"点击了取消按钮");

}]];

[self presentViewController:alert animated:YES completion:nil];

}

打电话、发短信、web以及发邮件的更多相关文章

  1. 打电话,发短信,发邮件,app跳转

    1.打电话 - (IBAction)callPhone1:(id)sender { NSURL *url = [NSURL URLWithString:@"tel://18500441739 ...

  2. iOS中如何切换到发短信、打电话、发邮件

    我们在做APP的时候,难免会遇到需要调用短信,电话等程序的时候.如美团. 当然,这些都只是一些简单的方法就可以实现,但是时间久了也会淡忘,所以想写这边博客.一是为了再捡起来复习一下,另一个相当于留个备 ...

  3. ios 设置亮度、声音;调用发短信、邮件、打电话

    一,设置亮度 [[UIScreen mainScreen] setBrightness:0.5];//0.0~1.0 二,设置声音 1,添加 MediaPlayer.framework 框架 2,在需 ...

  4. iOS 打电话、发短信、邮件、打开网址、调用应用等合集

    iOS中的很多功能都是非常简单的,几行代码就搞定了,比如打电话.打开网址.发邮件.发短信等,这里总结几个比较常用的: 1.打电话 方式一:最简单最直接的方式:直接跳到拨号界面 NSURL *url = ...

  5. html页面通过特殊链接:打电话,发短信,发邮件详细教程

    采用url href链接的方式,实现在Safari  ios,Android 浏览器,webos浏览器,塞班浏览器,IE,Operamini等主流浏览器,进行拨打电话功能. 1. 拨打电话 在电话号码 ...

  6. 移动设备wap手机网页html5通过特殊链接:打电话,发短信,发邮件详细教程

    如果需要在移动浏览器中实现拨打电话,调用sms发短信,发送email等功能,移动手机WEB页面(HTML5)Javascript提供的接口是一个好办法. 采用url href链接的方式,实现在Safa ...

  7. IOS,发短信,发邮件,打电话

    今天把APP里常用小功能 例如发短信.发邮件.打电话.全部拿出来简单说说它们的实现思路. 1.发短信实现打电话的功能,主要二种方法,下面我就分别说说它们的优缺点.1.1.发短信(1)——URL // ...

  8. Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)

    结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...

  9. WEB 移动网站 手机点击 打电话 发短信

    原文地址: http://www.blesswe.com/portal.php?mod=view&aid=428 我们在手机浏览网页是希望用户看到手机号码点击就可以直接打电话或发短信,下面我们 ...

随机推荐

  1. ES6笔记(4)-- Symbol类型

    系列文章 -- ES6笔记系列 Symbol是什么?中文意思是标志.记号,顾名思义,它可以用了做记号. 是的,它是一种标记的方法,被ES6引入作为一种新的数据类型,表示独一无二的值. 由此,JS的数据 ...

  2. IOS 字典快速转换为Model 模型

    一般情况下IOS得局部页面加载的过程是,创建一个Model然后,将Nib文件与Model进行关联,然后能够快速的获取到Nib文件上的控件实例.操作生成页面. 但是原生的内容是没有直接通过Json获取M ...

  3. 简单横道图Demo

    代码(每个月都显示整月): @{ ViewBag.Title = "横道图"; Layout = "~/Views/Shared/_Layout.cshtml" ...

  4. C#生成验证码

    生成验证码的类: using System; using System.Collections.Generic; using System.Drawing; using System.Text; na ...

  5. 利用chrome调试JavaScript代码

    看见网上很多人问怎么用chrome调试JavaScript代码,我也对这个问题抱着疑问,但是没有找到一篇能用的中文文章(可能我的google有问题),也不知道怎么点出一篇E文的,感觉作者写得不错,所以 ...

  6. [DBW]格式化时间

    Date.prototype.format = function(format) { //author: meizz let o = { , //月份 "d+": this.get ...

  7. webstorage[html5的本地数据处理]

    1.webStorage是什么? webStorage是html5中用于本地化存储的一种方式,而在之前呢我们是用cookie的存储方式处理; 2.那它们之间的区别是什么? Ⅰ.cookie存在的问题: ...

  8. Raising Error Conditions with MySQL SIGNAL / RESIGNAL Statements

    http://www.mysqltutorial.org/mysql-signal-resignal/ Summary: in this tutorial, you will learn how to ...

  9. 第 18 章 CSS 表格与列表

    学习要点: 1.表格样式 2.列表样式 3.其他功能 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 表格和列表,通过表格和列表的样式设置,让表格和列表显示更加多元化. 一.表格样式 表格有五 ...

  10. Scalaz(33)- Free :算式-Monadic Programming

    在任何模式的编程过程中都无法避免副作用的产生.我们可以用F[A]这种类型模拟FP的运算指令:A是可能产生副作用的运算,F[_]是个代数数据类型ADT(Algebraic Data Type),可以实现 ...