#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. qml基础学习 模型视图(一)

    一.理解qml模型和视图 qt的发展是迅速的,虽然在每一个release版本中或多或少都有bug,但是作为一个庞大的gui库,no,应该说是一个开发框架开说,qt已经算是做的相当好.qml部分是qt4 ...

  2. 【Android】Fragment的简单笔记

    被虐了,做某公司笔试时,发现自己连个Fragment的生命周期都写不详细.平时敲代码,有开发工具的便利,有网上各大神的文章,就算忘了也很容易的可以查到,但当要自己不借助外界,却发现自己似乎对该知识点并 ...

  3. Maven提高篇系列之(四)——使用Profile

    这是一个Maven提高篇的系列,包含有以下文章: Maven提高篇系列之(一)——多模块 vs 继承 Maven提高篇系列之(二)——配置Plugin到某个Phase(以Selenium集成测试为例) ...

  4. Android流量控制——列表页面

    1.最简单的模式: 设计: 1.将页码值传给服务器,让服务器返回对应的页码数据 2.数据缓存:只缓存第一页数据. 好处: 1.实现简单.无脑 坏处: 1.浪费流量,如果用户一直在等某个人发送消息的话. ...

  5. js无法对远程图片进行Base64转码

    web端图片转成Base64码报错 Image from origin 'http://114.215.87.123:8900' has been blocked from loading by Cr ...

  6. 【UWP】在不同类库使用ResourceDictionaries

    通常我们在类库中定义资源的时候可以在Theme/Generic.xaml中定义,当类库加载的时候,会自动加载Generic.xaml文件中的资源,通常用在控件库中,但如果控件多了之后,所有的Style ...

  7. c#单例模式的实现

    单例模式定义:一个类有且仅有一个实例,并且自行实例化向整个系统提供. 实现要点: 1.是单例模式的类只提供私有的构造函数.   2.是类定义中含有一个该类的静态私有对象. 3.是该类提供了一个静态的共 ...

  8. iOS阶段学习第30天笔记( UIViewController—Delegate(代理) )

    iOS学习(UI)知识点整理 一.UIViewController的介绍 1)概念:UIViewController 即视图控制器,用来管理和控制页面跳转的一个类 ,iOS里面采用了MVC的体系结构, ...

  9. wpf 自定义圆形按钮

    wpf 自定义圆形按钮 效果图 默认样式 获取焦点样式 点击样式 下面是实现代码: 一个是自定义控件类,一个是控件类皮肤 using System; using System.Collections. ...

  10. 导出Excel文件(针对Dev)

    文件类: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System. ...