ios 调用系统发短信以及打电话功能
先介绍一种最简单的方法:
调用打电话功能
[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
调用发短信功能
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10000"]];
上面的发短信的功能是调用系统的界面,下面是实现一种点击按键就直接发送短信,相当于后台发送,能不能上软件商店,还不能确定。相对建议来说,尽量使用第一种。
首先导入MFMessageComposeViewControllerDelegate这个代理,实现里面的方法
-(void)messageComposeViewController:(MFMessageComposeViewController *)controllerdidFinishWithResult:(MessageComposeResult)result {
//Notifies users about errors associated with the interface
switch (result) {
case MessageComposeResultCancelled:
if (DEBUG)NSLog(@"Result: canceled");
break;
case MessageComposeResultSent:
if (DEBUG)NSLog(@"Result: Sent");
break;
case MessageComposeResultFailed:
if (DEBUG)NSLog(@"Result: Failed");
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
群发短信:
- (IBAction)sendSMS {
BOOL canSendSMS = [MFMessageComposeViewControllercanSendText];
NSLog(@"can send SMS [%d]",canSendSMS);
if (canSendSMS) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc] init];
picker.messageComposeDelegate =self;
picker.navigationBar.tintColor = [UIColorblackColor];
picker.body = @"test";
picker.recipients = [NSArrayarrayWithObject:@"10086"];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
给一个人发短信:
从网页上获得内容
-(void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc] init];
picker.messageComposeDelegate =self;
UIWebView *web = nil;
NSMutableString* absUrl = [[NSMutableStringalloc] initWithString:web.request.URL.absoluteString];
[absUrl replaceOccurrencesOfString:@"http://i.aizheke.com"withString:@"http://m.aizheke.com"options:NSCaseInsensitiveSearchrange:NSMakeRange(0, [absUrllength])];
picker.body=[NSStringstringWithFormat:@"我在爱折客上看到:%@可能对你有用,推荐给你!link:%@",[webstringByEvaluatingJavaScriptFromString:@"document.title"],absUrl];
[absUrl release];
[self presentModalViewController:picker animated:YES];
[picker release];
}
事件绑定发送短信
-(IBAction)showSMSPicker:(id)sender {
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
if ([messageClass canSendText]) {
[self displaySMSComposerSheet];
}
else {
//设备没有短信功能
}
}
else {
// iOS版本过低,iOS4.0以上才支持程序内发送短信
}
}
ios 调用系统发短信以及打电话功能的更多相关文章
- iOS基本的发短信和打电话调用
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...
- iOS调用系统发送短信和邮件分享
//发送邮件 -(void)sendMail:(NSString*)subject content:(NSString*)content{ MFMailComposeViewController*co ...
- iOS中如何切换到发短信、打电话、发邮件
我们在做APP的时候,难免会遇到需要调用短信,电话等程序的时候.如美团. 当然,这些都只是一些简单的方法就可以实现,但是时间久了也会淡忘,所以想写这边博客.一是为了再捡起来复习一下,另一个相当于留个备 ...
- Android实现发短信与打电话的功能
//发短信 class SendMsgClickListener implements OnClickListener { public void onClick(View v) { //调用Andr ...
- linux下利用GPRS模块发短信、打电话
一.开发环境 内核版本:linux-3.0 开发板:FL2440(nandflash:K9F1G08 128M) GPRS模块:SIM900 二.与发短信和拨号相关的 AT 指 ...
- GPRS的短信和打电话功能
短信功能: 发短信设置文本格式就可以了:但收短信可能收到的是乱码,需要编写解码程序才可以: 关于打电话单片机复位功能: 首先要建立黑白名单制度过滤手机号,只运行白名单的手机对的单片机打电话:其它的不响 ...
- IOS 掉用系统发短信
#import <MessageUI/MessageUI.h> MFMessageComposeViewControllerDelegate #pragma mark - 调用ios系统短 ...
- android发短信,打电话
//1.进入系统短信列表界面 Intent intent = newIntent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_DEF ...
- IOS程序内发短信 MFMessageComposeViewController
文章转载地址:http://www.headsky.org/?p=63 iOS4.0新加入了MFMessageComposeViewController和MFMessageComposeViewCon ...
随机推荐
- 定位导致物化视图无法快速刷新的原因 分类: H2_ORACLE 2013-08-08 23:04 335人阅读 评论(0) 收藏
转载自:http://yangtingkun.itpub.net/post/468/13318 物化视图的快速刷新采用了增量的机制,在刷新时,只针对基表上发生变化的数据进行刷新.因此快速刷新是物化视图 ...
- 应用 Valgrind 发现 Linux 程序的内存问题及交叉编译for arm
Valgrind 概述 体系结构 Valgrind是一套Linux下,开放源代码(GPL V2)的仿真调试工具的集合.Valgrind由内核(core)以及基于内核的其他调试工具组成.内核类似于一个框 ...
- [Angular Directive] Combine HostBinding with Services in Angular 2 Directives
You can change behaviors of element and @Component properties based on services using @HostBinding i ...
- Android下载文件提示文件不存在。。。 java.io.FileNotFoundException
遇到这个错误java.io.FileNotFoundException,事实上文件是存在的,把地址复制到手机浏览器都能够直接下载的,但为嘛不能下载呢. Error in downloadBitmap ...
- Windows下的bat中文乱码问题
起初拿到一个bat文件,我在修改时看到编码是gb2312,我就直接将其转变为了utf8...但是在执行后的黑窗口出现中文乱码问题,最后网上获取帮助是修改编码为ANSI编码,确实不出现乱码了,ANSI是 ...
- XMPP之安装mySQL--Mac OS(一)
come from:http://www.cnblogs.com/xiaodao/archive/2013/04/04/2999426.html 一.安装 到MySQL官网上http://dev.my ...
- BZOJ 1509 逃学的小孩 - 树型dp
传送门 题目大意: 在一棵树中, 每条边都有一个长度值, 现要求在树中选择 3 个点 X.Y. Z , 满足 X 到 Y 的距离不大于 X 到 Z 的距离, 且 X 到 Y 的距离与 Y 到 Z 的距 ...
- 过滤Filter推断用户是否登录
WEB.XML <!-- 用户session的 键 sessionKEY --> <context-param> <param-name>userSessionKe ...
- 【u115】&&【t031】 01迷宫
01迷宫(maze01) Time Limit: 1 second Memory Limit: 128 MB [问题描述] 有一个仅由数字0与1组成的n×n格迷宫.若你位于一格0上,那么你可以移动到相 ...
- KMP算法具体解释(贴链接)
---------------------------------------------------------------------------------------------------- ...