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的支持已经很不错 ...
随机推荐
- 服务器跟VPS有什么区别
你好. 服务器是独立的真实存在的硬件设备.其实也就是一台高端电脑.他是放在机房运行的.主要为网站以及一些软件应用提供运行平台.而VPS是虚拟服务器.他是利用软件在服务器上虚拟出来的.也就是分配出一部分 ...
- Java中long和Long有什么区别 (转载)
“Long is a class. long is a primitive. That means Long can be null, where long can't. Long can go an ...
- Delphi 2 Unleashed (一) 介绍
原书作者是作者是 Charles Calvert,国内翻译为<Delphi 2 程序设计大全>,由横空翻译组翻译,机械工业出版社1997年12月出版,看网上评论和介绍,该书是系统学习 De ...
- hdu 2203 亲和串
把T串扩展成两倍 然后KMP 注意T的长度要大于P的长度 #include <iostream> #include <cstdio> #include <cstri ...
- HTTP状态码(HTTP Status Code)及常用场景
常见的状态码: HTTP: Status 200 – 服务器成功返回网页HTTP: Status 3xx - 表示要完成请求,需要进一步操作. 通常,这些状态代码用来重定向HTTP: Status 4 ...
- ip校验方法:判断ip是否位于指定的范围内
import java.util.ArrayList;import java.util.List;import java.util.regex.Matcher;import java.util.reg ...
- jquery获取元素的值,获取当前对象的父对象等等
jsp代码: <span><input type="hidden" value="1" id="newInfo">& ...
- Ant自动编译打包&发布 android项目
Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我们自动编译打包了. ...
- WPF 获取程序路径的一些方法,根据程序路径获取程序集信息
一.WPF 获取程序路径的一些方法方式一 应用程序域 //获取基目录即当前工作目录 string str_1 = System.AppDomain.CurrentDomain.BaseDirector ...
- 使用ueditor小结
1. 导入 js: ueditor.config.js ueditor.all.js css/images/plugin: themes lang dialog(可选) third-party(可选) ...