Ios 当按下按钮时,如何打开通话/拨号号码视图打开?

Ios 当按下按钮时,如何打开通话/拨号号码视图打开?,ios,objective-c,uibutton,phone-call,Ios,Objective C,Uibutton,Phone Call,} 在上面的代码中,我使用了各种方法,但没有人工作。当我在函数上实现一个断点时,它会说这超出了范围。这有什么问题?您应该删除电话号码中的hypens“-”,以及括号“(“,”)。除数字外,不应有特殊字符 enter code here-(IBAction)Call:(id)sender{ //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://18005551234"]]; /*NSString *pho

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

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

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

您可以根据需要使用任何方法。如果手机号码是动态的,您可以将其保存在单独的变量中,并使用stringWithFormat:method将其追加。哪一个更好?在模拟器中,任何一个都可以工作。请编写正在使用的代码行。谢谢Jim Thio,我现在已经添加了;-)
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];