iOS app发送短信

1.导入MessageUI.framework

2.ViewController中

#import <MessageUI/MessageUI.h>

创建一个按钮触发发短信的方法

UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];

btn.frame = CGRectMake(150, 150, 50, 50);

[self.view addSubview:btn];

[btn addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];

[btn setTitle:@"邀请" forState:UIControlStateNormal];

btn.backgroundColor = [UIColor greenColor];

- (void)btn:(UIButton *)sender {

[self showMessageView:[NSArray arrayWithObject:@"17006698689"] title:@"测试" body:@"测试1"];

}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

[self dismissViewControllerAnimated:YES completion:^{

switch (result) {

case MessageComposeResultSent:

{

//信息传送成功

}

break;

case MessageComposeResultFailed:

{

//信息传送失败

}

break;

case MessageComposeResultCancelled:

{

//消息被用户取消传送

{

}

}

break;

default:

break;

}

}];

}

//发送短信

-(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 {

NSLog(@"该设备不支持短信功能");

}

}

时间: 2024-08-30 02:58:54

iOS app发送短信的相关文章

iOS中发送短信/发送邮件的实现 韩俊强的博客

需要引入框架: MessageUI.framework 布局如下: 短信和邮件: #import "ViewController.h" #import <MessageUI/MessageUI.h> @interface ViewController ()<MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>//遵循协议 @end @implementation V

各大APP注册时发送短信验证码是怎么实现的?

回答这个问题可以从多个角度来回答,比如商务角度和技术角度,为了快速清晰的让广大的读者了解这个过程,本文我们从商务角度来深入分析. 实现原理 现各大APP发送短信的服务一般是由第三方短信服务商提供的,他们整合了移动,联通.电信三方资源,三网都可以发送,这样就不需要直接对接运营商了. 发送短信验证码主要是为了验证手机方的真实性,实现原理简单说就是系统先生成一个验证码,调用第三方服务商的短信接口,发送到手机方,手机方输入验证码,再由系统去校验是否符合,符合则说明手机真实有效. 服务商选择 提供短信接入

iOS+Swift: 使用MessageUI.framework发送短信

在iOS中, 可以使用MessageUI.framework框架发送短信, 步骤如下: 代码下载http://git.oschina.net/yao_yu/swift_cnblogs_samples/tree/master/Y0001_SendSMS 添加MessageUI.framework框架 为ViewController类 添加UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate 接口 实现func

iOS发送短信

iPhone开发,发送短信的方法: iPhone开发中,发送短信方法有二: 1.URL Scheme,这样不可以设置短信内容 1 2 3 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]]; //打电话可以这样 //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086

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

一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_phoneNumber]]]; 二.发送短消息界面 调用系统的发送短信的界面,需要引入以下头文件: #import <MessageUI/MessageUI.h> 系统短信界面的调用很简单,只需下面几句代码: ? 1 2 3 4 5         

ios打电话发短信接口

电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10010"]];//打电话 使用openURL这个API打电话结束后,返回的是系统的拨打电话界面,如何才能返回自己的应用呢?有两种方法与大家分享. 第一种是用UIWebView加载电话,这种是合法的,可以上A

IOS,发短信,发邮件,打电话

今天把APP里常用小功能 例如发短信.发邮件.打电话.全部拿出来简单说说它们的实现思路. 1.发短信实现打电话的功能,主要二种方法,下面我就分别说说它们的优缺点.1.1.发短信(1)——URL // 直接拨号,拨号完成后会停留在通话记录中1.方法: NSURL *url = [NSURL URLWithString:@"sms://10010"]; [[UIApplication sharedApplication] openURL:url]; 2.优点:–简单3.缺点:–不能指定短信

拨打电话与发送短信功能

设计界面如下图如示,在编辑框中只接受电话号码,实现“拨打电话”和“发送短信”的功能 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools"

java 学习第13课,android 实现发送短信的功能

1. 界面布局 界面代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView andro