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的支持已经很不错 ...
随机推荐
- 【1】CommonCode快速代码集
阅读目录 CommonCode是什么? CommonCode包括哪些内容? 版本信息 回到顶部 CommonCode是什么? 简单的说,CommonCode是作者在经历各种"试错&quo ...
- [算法导论]迪克斯特拉算法 @ Python
class Graph: def __init__(self): self.V = [] self.w = {} class Vertex: def __init__(self, x): self.k ...
- delphi使用outputdebugstring调试程序和写系统日志
delphi使用outputdebugstring调试程序和写系统日志 procedure TForm1.btn1Click(Sender: TObject); begin OutputDebugSt ...
- jackson 实体转json 为NULL或者为空不参加序列化
1.实体上 @JsonInclude(Include.NON_NULL) //将该标记放在属性上,如果该属性为NULL则不参与序列化 //如果放在类上边,那对这个类的全部属性起作用 //Include ...
- pgpgin|pgpgout|pswpin|pswpout意义与差异
引用来自: http://ssms.cs2c.com.cn/otrs/pc.pl?Action=PublicFAQZoom;ItemID=11741 文章主要意思是: 1. page in/out操作 ...
- 【LeetCode】258. Add Digits (2 solutions)
Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...
- [转] The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing
https://www.smartftp.com/support/kb/the-program-cant-start-because-api-ms-win-crt-runtime-l1-1-0dll- ...
- Web - 客户端存储的几种方式
客户端存储主要方便一些APP离线使用.今天就来说说客户端存储的方法有多少? 说在最前面的一句:所有的客户端存储都有一个原则:读写的数据必须要同域 1 Cookie Cookie是一项很老的技术的,就是 ...
- C#集合 -- Equality和Order插件
在前面的文章C#相等性比较和C#排序比较中,我已经叙述了类型相等,类型哈希,和类型比较的.NET标准协议.实现了这些协议的类型在一个字典或者列表中也可以正常工作.但是需要注意的是: 只有当类型的Equ ...
- android中的layoutparams参数使用的简单总结
定义: 我们可以在Android的framework中的ViewGroup类里找到定义的类: public static class LayoutParams{...} 此类有如下注释: Layout ...