首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按下按钮后如何打开call making /dialing numer视图?

按下按钮后如何打开call making /dialing numer视图?
EN

Stack Overflow用户
提问于 2011-07-09 17:07:23
回答 1查看 531关注 0票数 1
代码语言:javascript
复制
enter code here-(IBAction)Call:(id)sender{
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://18005551234"]];
/*NSString *phoneStr = [[NSString alloc] initWithFormat:@"tel:%@",phoneNumber.text];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];*/
NSURL *url = [ [ NSURL alloc ] initWithString: @"tel:212-555-1234" ];
[[UIApplication sharedApplication] openURL:url]; 

}在上面的代码中,我使用了各种方法,但没有人工作。当我在函数上实现一个断点时,它会说这超出了范围。这里面有什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-09 18:10:17

你应该去掉电话号码中的连字符"-“和括号"(",")”。除数字外,不应包含任何特殊字符。

代码语言:javascript
复制
NSCharacterSet *specialCharSet = [NSCharacterSet characterSetWithCharactersInString:@" )(-,"];
NSArray *components = [phoneNumber.text componentsSeparatedByCharactersInSet:specialCharSet];
NSString *phoneStr = [components componentsJoinedByString:@""];
phoneStr = [NSString stringWithFormat:@"tel:%@", phoneStr];
NSURL *url = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:url]; 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6633844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档