您的位置:首页 > 移动开发 > IOS开发

iOS关于拨打电话和发送短信的用法

2015-01-14 00:00 441 查看
在做开发的过程中会经常遇到一些要调用拨号和发短信的功能。这里整理了一下。

1,首先来看看发短信,直接上代码
NSArray *phoneArray = [NSArray arrayWithObjects:@"18212341234", nil];
NSString *text = [NSString stringWithFormat:@"这是测试短信,收到请勿回复"];
[self sendSMS:text recipientList:phoneArray];

说明一下,手机号码放在phoneArray数组里,如果需要给多人发送短信的话就比较方便了。text里就是要发送短信的内容

2,拨号

NSString *phone = @"18212341234";
UIWebView *callWebview =[[UIWebView alloc] init];
NSString *telUrl = [NSString stringWithFormat:@"tel:%@",phone];
NSURL *url = [[NSURL alloc] initWithString:telUrl];
[callWebview loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:callWebview];

这个方法拨号前会自动弹框让你选择是否确定拨号,拨号结束后会返回到你的当前的程序

3,拨号

NSString *phoneString = @"18212341234";
UIWebView *callWebview =[[UIWebView alloc] init];
NSString *telUrl = [NSString stringWithFormat:@"tel:%@",phoneString];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
[self.view addSubview:callWebview];

这个方法的拨号不会弹框提醒你让你确定是否确定拨号,而是直接拨号,并且拨号结束后停留在系统自带的通话记录里。不会返回到之前的程序。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: