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_拨打电话/发送短信的更多相关文章

  1. Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘

    apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...

  2. android 入门 002 (拨打电话,发送短信)

    一.拨打电话 1.首先做好界面,代码如下: layout =>activity_main.xml 中 <LinearLayout xmlns:android="http://sc ...

  3. 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信

    1.Flutter url_launcher 模块    Flutter url_launcher 模块可以让我们实现打开外部浏览器.打开外部应用.发送短信.拨打电话等功能.    https://p ...

  4. Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序

    家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...

  5. IOS中调用系统拨打电话发送短信

    一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...

  6. android使用Intent操作拨打号码发送短信

    Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...

  7. html5 安卓拨打电话 发短信

    方法一: <input name=”phone_no” format=”*m” value=”13″/> <do type=”option” label=”呼出号”> < ...

  8. ios调用本地拨打电话,发送短信

    电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话   [[UIApplication sharedApplicat ...

  9. a标签的妙用-拨打电话、发送短信、发送邮件

    前端时间在做手机WAP网站时,遇到需要点击页面上显示的电话号能直接拨号的需求,查找资料发现可以使用html的a标签完美实现该需求!记录下来以备后用...... 目前主流手机浏览器对H5的支持已经很不错 ...

随机推荐

  1. Android系列--DOM、SAX、Pull解析XML

    您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注按钮 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐按钮 来支持一下哦 如果您对文章内 ...

  2. delphi使用outputdebugstring调试程序和写系统日志

    delphi使用outputdebugstring调试程序和写系统日志 procedure TForm1.btn1Click(Sender: TObject); begin OutputDebugSt ...

  3. [转]java byte 数据类型(基础)

    package com.suypower.chengyu.test; public class ByteTest { /** * byte 8 bits -128 - + 127 * 1 bit = ...

  4. 有时候为了方便sql语句的对比和查询,我们可以使用declare来定义变量 上下篇的问题

    --定义一些参数 declare @nodeId int,@ekid int ,@ecid int,@eid int,@pid int --列表 SELECT * FROM ( SELECT *,RO ...

  5. jquery.pjax.js bug问题解决集锦

    jquery.pjax 是一个很好的局部刷新插件,但实际应用过程是还是会有很多小问题,部分问题解决如下: 1.pjax 局部加载时候,IE 存在缓存问题,很容易理解,pjax是通过jquery的aja ...

  6. css blur 的兼容写法

    出自:小tip: 使用CSS将图片转换成模糊(毛玻璃)效果 .blur { filter: url(blur.svg#blur); /* IE10, IE11 */ -webkit-filter: b ...

  7. ikvm.net简介

    ikvm.net是什么 http://www.ikvm.net/ ikvm.net是能够运行在mono和.net framework的java虚拟机.它包括了 在.net中实现的一个java虚拟机 j ...

  8. c#操作word表格

    http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...

  9. Android-NDK编译:cocos2d-x(三) eclipse 导入工程

    NDK 编译后,用eclipse导入cocos2d-x工程 菜单[File]-->[New]-->[Project] ,弹出New Project 对话框 窗口下方 选 [Android] ...

  10. apk签名

    参考:http://stackoverflow.com/questions/13578134/how-to-automate-keystore-generation-using-the-java-ke ...