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]; }在上面的代码中,我使用了各种方法,但没有人工作。当我在函数上实现一个断点时,它会说这超出了范围。这里面有什么问题?
发布于 2011-07-09 18:10:17
你应该去掉电话号码中的连字符"-“和括号"(",")”。除数字外,不应包含任何特殊字符。
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]; https://stackoverflow.com/questions/6633844
复制相似问题