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 我们在手机浏览网页是希望用户看到手机号码点击就可以直接打电话或发短信,下面我们 ...
随机推荐
- HDU 3966 Aragorn's Story 树链剖分+树状数组 或 树链剖分+线段树
HDU 3966 Aragorn's Story 先把树剖成链,然后用树状数组维护: 讲真,研究了好久,还是没明白 树状数组这样实现"区间更新+单点查询"的原理... 神奇... ...
- vs 中统计代码行数
------解决方案--------------------b*[^:b#/]+.*$^b*[^:b#/]+.*$ ctrl + shift + F 查找选项勾选 正则表达式
- 1千万英国用户被Cryptolocker勒索软件瞄准
英国国家打击犯罪调查局(NCA)发布国家紧急警报,警报一场大规模的垃圾邮件,这些邮件中包含了一款名为CryptoLocker的勒索程序,把目标瞄准了1千万英国的email用户,该程序会加密用户的文档, ...
- js实现图片预览
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- win环境 yii2 框架 overtrue/wechat 包 由 sys_get_temp_dir 引发的 the directory "c:\Windows" is not writable
vendor\overtrue\wechat\src\Foundation\Application.php registerBase 方法 在初始化属性时 $this['cache'] = funct ...
- 用Runtime.getRuntime().exec()需要注意的地方
有时候我们可能需要调用系统外部的某个程序,此时就可以用Runtime.getRuntime().exec()来调用,他会生成一个新的进程去运行调用的程序. 此方法返回一个java.lang.Proce ...
- spout详解
spout放在每个executer执行,我们先从spoutExecutors的初始化开始往下看,spoutExecutors是在一个worker中管理其中的tasks,在SpoutExecutors的 ...
- 【初级】linux mkdir 命令详解及使用方法实战
mkdir命令详解及使用方法实战 名称 MKDIR 是 make directories 的缩写 使用方法 mkdir [选项(如-p)] ...目录名称(及子目录注意用分隔符隔开)... 如使 ...
- JSP内置对象---out内置对象
<%@ page language="java" import="java.util.*" contentType="text/html; ch ...
- Spark机器学习读书笔记-CH03
3.1.获取数据: wget http://files.grouplens.org/datasets/movielens/ml-100k.zip 3.2.探索与可视化数据: In [3]: user_ ...