iOS_拨打电话/发送短信
GitHub address : https://github.com/mancongiOS/makeACallAndSendMessage.git
功能一: 拨打电话
1.可以有提示框.提示该电话号码 是否拨打.
2.直接跳转到拨打电话页面.
3.拨打完成之后,跳转回APP.
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"12345678911"];
UIWebView * callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
[self.view addSubview:callWebview];
功能二: 发送短信
1.导入系统framework --> MessageUI.framework
2.导入头文件 #import <MessageUI/MessageUI.h>
3.遵守协议 <MFMessageComposeViewControllerDelegate>
4.书写按钮调用方法
-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
if( [MFMessageComposeViewController canSendText] )
{
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
controller.recipients = phones;
controller.navigationBar.tintColor = [UIColor redColor];
controller.body = body;
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
message:@"该设备不支持短信功能"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alert show];
}
}
5.代理方法
#pragma mark - MFMessageComposeViewController
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)( * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil]; }); switch (result) {
case MessageComposeResultSent:
//信息传送成功 break;
case MessageComposeResultFailed:
//信息传送失败 break;
case MessageComposeResultCancelled:
//信息被用户取消传送 break;
default:
break;
}
}
上代码
#import "ViewController.h"
#import <MessageUI/MessageUI.h> #define kScreenSize [UIScreen mainScreen].bounds.size @interface ViewController () <MFMessageComposeViewControllerDelegate> @property (nonatomic, strong) UIButton * phoneButton;
@property (nonatomic, strong) UIButton * messageButton; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; [self initUI];
} #pragma mark - MFMessageComposeViewController
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)( * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil]; }); switch (result) {
case MessageComposeResultSent:
//信息传送成功 break;
case MessageComposeResultFailed:
//信息传送失败 break;
case MessageComposeResultCancelled:
//信息被用户取消传送 break;
default:
break;
}
} #pragma mark - 点击事件
- (void)phoneButtonClikced { NSString * moble = @""; NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",moble]; UIWebView * callWebview = [[UIWebView alloc] init]; [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]]; [self.view addSubview:callWebview];
} - (void)messageButtonClikced { [self showMessageView:[NSArray arrayWithObjects:@"",@"", nil] title:@"test" body:@"你是土豪么,么么哒"];
} #pragma mark - 实现方法
- (void)initUI {
[self.view addSubview:self.phoneButton]; [self.view addSubview:self.messageButton];
} -(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
if( [MFMessageComposeViewController canSendText] )
{
MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
controller.recipients = phones;
controller.navigationBar.tintColor = [UIColor redColor];
controller.body = body;
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
message:@"该设备不支持短信功能"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alert show];
}
} #pragma mark - setter & getter
- (UIButton *)phoneButton {
if (_phoneButton == nil) {
self.phoneButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.phoneButton.frame = CGRectMake(, , kScreenSize.width - , );
self.phoneButton.backgroundColor = [UIColor orangeColor];
[self.phoneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.phoneButton setTitle:@"拨打电话" forState:UIControlStateNormal];
[self.phoneButton addTarget:self action:@selector(phoneButtonClikced) forControlEvents:UIControlEventTouchUpInside];
} return _phoneButton;
} - (UIButton *)messageButton {
if (_messageButton == nil) {
self.messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.messageButton.backgroundColor = [UIColor orangeColor];
self.messageButton.frame = CGRectMake(, , kScreenSize.width - , ); [self.messageButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.messageButton setTitle:@"发送短信" forState:UIControlStateNormal];
[self.messageButton addTarget:self action:@selector(messageButtonClikced) forControlEvents:UIControlEventTouchUpInside];
} return _messageButton;
} @end
iOS_拨打电话/发送短信的更多相关文章
- Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘
apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...
- android 入门 002 (拨打电话,发送短信)
一.拨打电话 1.首先做好界面,代码如下: layout =>activity_main.xml 中 <LinearLayout xmlns:android="http://sc ...
- 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信
1.Flutter url_launcher 模块 Flutter url_launcher 模块可以让我们实现打开外部浏览器.打开外部应用.发送短信.拨打电话等功能. https://p ...
- Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序
家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...
- IOS中调用系统拨打电话发送短信
一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...
- android使用Intent操作拨打号码发送短信
Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...
- html5 安卓拨打电话 发短信
方法一: <input name=”phone_no” format=”*m” value=”13″/> <do type=”option” label=”呼出号”> < ...
- ios调用本地拨打电话,发送短信
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicat ...
- a标签的妙用-拨打电话、发送短信、发送邮件
前端时间在做手机WAP网站时,遇到需要点击页面上显示的电话号能直接拨号的需求,查找资料发现可以使用html的a标签完美实现该需求!记录下来以备后用...... 目前主流手机浏览器对H5的支持已经很不错 ...
随机推荐
- LeakCanary 中文使用说明
http://www.liaohuqiu.net/cn/posts/leak-canary-read-me/ LeakCanary 中文使用说明 分享到:新浪微博微信 10 May 2015 Leak ...
- Java 周历日历
WeekCalendarUtils工具类代码,传入起始日期即可返回对应日期的周历日历,年月部分添加周数统计 import java.util.Calendar; import java.util.Da ...
- nginx+tomcat+java部署总结
昨天部署了一下nginx+tomcat+java出现了很多问题,以下为整理总结. 使用了两种部署方式,一种是源码部署,一种是war部署. java源码部署总结: 环境:nginx+tomcat 部署方 ...
- hdu 1845
一看题意就是二分匹配问题,建边是双向的,两个集合都是n个点 这题的图很特殊,每个点都要与三个点相连,在纸上画了六个点的图就感觉此图最大匹配肯定是六,除以2就是原图的匹配了,就感觉这样的图肯定会达到满匹 ...
- Scala 深入浅出实战经典 第42讲:scala 泛型类,泛型函数,泛型在spark中的广泛应用
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...
- <《基金经理投资笔记丛书4-1:投资是一种生活方式》>
在中国股市每年能获得10%的收益已经是非常好了,但问题是大多数股民不认为这是一个很高的收益水平,尽管现实中大多数股民的收益状况比这要差很多. 投资中一个重要的心理陷阱是过度自信,过度自信的一个主要表现 ...
- selenium 3.0发布
记得3年前selenium core team就放出风声selenium3.0将在某个圣诞节发布,然而大家等了3年,就在所有人都不再关注selenium进度的时候,selenium3.0 beta1悄 ...
- akka cluster sharding source code 学习 (1/5) 替身模式
为了使一个项目支持集群,自己学习使用了 akka cluster 并在项目中实施了,从此,生活就变得有些痛苦.再配上 apache 做反向代理和负载均衡,debug 起来不要太酸爽.直到现在,我还对 ...
- vs2010 rdlc .net4.0 卸载 Appdomain 时出错。 (异常来自 HRESULT:0x80131015) 解决办法
网上一看Appdomain出错,绝大部分都是说控件加载错误.经测试在.net 4.0环境下 rdlc报表很容易发生卸载 Appdomain 时出错. (异常来自 HRESULT:0x80131015) ...
- 在自己的框架中引用 PHPExcel
如果直接在框架中的controller中直接引用 xxxx/PHPExcel.php,由于框架中有autoload 与PHPExcel的autoload冲突(加载目录原因), 那么在不想做太多修改的情 ...