如何打开按下按钮时打开的呼叫/拨号号码视图?

发布于 2024-11-19 08:27:50 字数 581 浏览 5 评论 0原文

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]; 

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

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]; 

}
in above code i use various method but no one working. when i implement a break-point on function then it say this is out of scope. what is problem in this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长伴 2024-11-26 08:27:50

您应该删除电话号码中的连字符“-”以及方括号“(”、“)”。除数字外不应有特殊字符。

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]; 

You should remove the hypens "-", and also the brackets "(", ")" from the phone number. No special characters should be there except numbers.

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]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文