iOS 打电话 发短信(转载)
官方代码
发短息和邮件添加MessageUI.framework 库
发送信息
- (IBAction)showSMSPicker:(id)sender
{
// You must check that the current device can send SMS messages before you
// attempt to create an instance of MFMessageComposeViewController. If the
// device can not send SMS messages,
// [[MFMessageComposeViewController alloc] init] will return nil. Your app
// will crash when it calls -presentViewController:animated:completion: with
// a nil view controller.
if ([MFMessageComposeViewControllercanSendText])
// The device can send email.
{
[selfdisplaySMSComposerSheet];
}
else
// The device can not send email.
{
self.feedbackMsg.hidden =NO;
self.feedbackMsg.text = @"Device not configured to send SMS.";
}
- (void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc] init];
picker.messageComposeDelegate =self;
picker.navigationBar.tintColor = [UIColorblackColor];
picker.recipients = [NSArrayarrayWithObject:@"186888888"];
picker.body =@"Hello from California!";
[selfpresentViewController:picker animated:YEScompletion:NULL];
}
// -------------------------------------------------------------------------------
// messageComposeViewController:didFinishWithResult:
// Dismisses the message composition interface when users tap Cancel or Send.
// Proceeds to update the feedback message field with the result of the
// operation.
// -------------------------------------------------------------------------------
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result
{
self.feedbackMsg.hidden =NO;
// Notifies users about errors associated with the interface
switch (result)
{
caseMessageComposeResultCancelled:
self.feedbackMsg.text = @"Result: SMS sending canceled";
break;
caseMessageComposeResultSent:
self.feedbackMsg.text = @"Result: SMS sent";
break;
caseMessageComposeResultFailed:
self.feedbackMsg.text = @"Result: SMS sending failed";
break;
default:
self.feedbackMsg.text = @"Result: SMS not sent";
break;
}
[selfdismissViewControllerAnimated:YEScompletion:NULL];
}
发送邮件
- (IBAction)showMailPicker:(id)sender
{
// You must check that the current device can send email messages before you
// attempt to create an instance of MFMailComposeViewController. If the
// device can not send email messages,
// [[MFMailComposeViewController alloc] init] will return nil. Your app
// will crash when it calls -presentViewController:animated:completion: with
// a nil view controller.
if ([MFMailComposeViewControllercanSendMail])
// The device can send email.
{
[selfdisplayMailComposerSheet];
}
else
// The device can not send email.
{
self.feedbackMsg.hidden =NO;
self.feedbackMsg.text =@"Device not configured to send mail.";
}
}
#pragma mark - Compose Mail/SMS
// -------------------------------------------------------------------------------
// displayMailComposerSheet
// Displays an email composition interface inside the application.
// Populates all the Mail fields.
// -------------------------------------------------------------------------------
- (void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewControlleralloc] init];
picker.mailComposeDelegate =self;
[picker setSubject:@"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArrayarrayWithObject:@"first@example.com"];
NSArray *ccRecipients = [NSArrayarrayWithObjects:@"second@example.com",@"third@example.com", nil];
NSArray *bccRecipients = [NSArrayarrayWithObject:@"fourth@example.com"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundlemainBundle] pathForResource:@"rainy"ofType:@"jpg"];
NSData *myData = [NSDatadataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/jpeg"fileName:@"rainy"];
// Fill out the email body text
NSString *emailBody =@"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[selfpresentViewController:picker animated:YEScompletion:NULL];
}
#pragma mark - Delegate Methods
// -------------------------------------------------------------------------------
// mailComposeController:didFinishWithResult:
// Dismisses the email composition interface when users tap Cancel or Send.
// Proceeds to update the message field with the result of the operation.
// -------------------------------------------------------------------------------
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
self.feedbackMsg.hidden =NO;
// Notifies users about errors associated with the interface
switch (result)
{
caseMFMailComposeResultCancelled:
self.feedbackMsg.text = @"Result: Mail sending canceled";
break;
caseMFMailComposeResultSaved:
self.feedbackMsg.text = @"Result: Mail saved";
break;
caseMFMailComposeResultSent:
self.feedbackMsg.text = @"Result: Mail sent";
break;
caseMFMailComposeResultFailed:
self.feedbackMsg.text = @"Result: Mail sending failed";
break;
default:
self.feedbackMsg.text = @"Result: Mail not sent";
break;
}
[selfdismissViewControllerAnimated:YEScompletion:NULL];
}
打电话 我只写了一种简单的方式 还有其他的
添加 AddressBookUI.framework 库
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABMultiValue.h>
#import <AddressBook/ABRecord.h>
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [keyArrayobjectAtIndex:indexPath.row];
NSArray *array = [tableDataDictionaryobjectForKey:key];
NSString *phoneNum = [arrayobjectAtIndex:1];//电话号码
NSURL *phoneURL = [NSURLURLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];
if ( !_phoneCallWebView ) {
_phoneCallWebView = [[UIWebViewalloc] initWithFrame:CGRectZero];
}
[_phoneCallWebViewloadRequest:[NSURLRequest requestWithURL:phoneURL]];
}
iOS 打电话 发短信(转载)的更多相关文章
- iOS - 打电话, 发短信
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...
- ios打电话发短信接口
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...
- 向android模拟器打电话发短信的简单方法
在开发android应用程序时,有时候需要测试一下向android手机拨打电话发送短信时该应用程序的反应.譬如编写一个广播接收器,来提示用户有短信收到或者处理短信,就需要向该手机发送短信来进行测试.这 ...
- iOS开发之调用系统打电话发短信接口以及程序内发短信
在本篇博客开头呢,先说一下写本篇的博客的原因吧.目前在做一个小项目,要用到在本应用程序内发验证码给其他用户,怎么在应用内发送短信的具体细节想不大起来了,于是就百度了一下,发现也有关于这方面的博客,点进 ...
- iOS开发中打电话发短信等功能的实现
在APP开发中,可能会涉及到打电话.发短信.发邮件等功能.比如说,通常一个产品的"关于"页面,会有开发者的联系方式,理想情况下,当用户点击该电话号码时,能够自动的帮用户拨出去,就涉 ...
- IOS,发短信,发邮件,打电话
今天把APP里常用小功能 例如发短信.发邮件.打电话.全部拿出来简单说说它们的实现思路. 1.发短信实现打电话的功能,主要二种方法,下面我就分别说说它们的优缺点.1.1.发短信(1)——URL // ...
- h5打电话发短信写邮件怎么实现
// 一.打电话<a href="tel:0755-10086">打电话给:0755-10086</a> // 二.发短信,winphone系统无效< ...
- 打电话,发短信,发邮件,app跳转
1.打电话 - (IBAction)callPhone1:(id)sender { NSURL *url = [NSURL URLWithString:@"tel://18500441739 ...
- WEB 移动网站 手机点击 打电话 发短信
原文地址: http://www.blesswe.com/portal.php?mod=view&aid=428 我们在手机浏览网页是希望用户看到手机号码点击就可以直接打电话或发短信,下面我们 ...
随机推荐
- 在Oracle中使用Entity Framework 6 CodeFirst
项目中需要将系统从SQLServer数据库迁移到Oracle上.由于原大部分数据访问操作都是通过包装了Entity Framework的统一访问入口实现的,所以需要研究Entity Framework ...
- HDU 4938 Seeing People(2014 Multi-University Training Contest 7)
思路:根据出发时间把点往速度反方向移动 t*v的 的距离这样就可以当成 全部点一起出发,再把y轴上的点固定不动相当于x轴的点向(-v2,v1)方向移动 .可以把所有点映射到x轴上进行统计即可(要记住同 ...
- solution to E: failed to fetch .......
There are some issues today for me that my desktop can't boot as I expected, I installed windows 8.1 ...
- href链接的地址
tencent://message/?uin=QQ号. 链接一个弹出框.指向一个QQ号.
- js 简繁体字转换
有些项目需要用到简体和繁体两种字体,在js前台进行转换比较方便而且显示速度没有延时 是一个比较好的解决方案. var _isFT_CS = 0// 简体 var _isFT_CT = 1// 繁体 v ...
- python学习——将while循环改成函数
笨办法学python第33节 这一节主要学习内容是while循环,记录内容为将while改成函数,首先源代码如下: i = 0 numbers = [] while i < 6: print & ...
- FTP Proxy Server
本文将在Linux环境下实现一个简单的FTP代理服务器,主要内容涉及FTP主动/被动模式和简单的Socket编程. 1. 主动模式和被动模式 FTP有两种模式,即主动模式(Active Mode)和被 ...
- django:field字段类型
字段类型(Field types) AutoField 它是一个根据 ID 自增长的 IntegerField 字段.通常,你不必直接使用该字段.如果你没在别的字段上指定主 键,Django 就会自动 ...
- OC基础--结构体 枚举做类成员属性
结构体 枚举作类的成员属性: 定义一个学生类 性别 -- 枚举 生日 入学日期 毕业日期 -- 结构体 代码示例: 声明文件 Student.h: #import <Foundation ...
- C#按行读取文本并存放再数组内
我只想说真的是日了狗的麻烦,代码就那么几行,但是根本看不懂在搞些什么东西,我现在还是一点都不知道getline函数到底是怎么用的,但是事实就是他确实能用. 期间在那该死的第一个char根本不知道为什么 ...