【问题标题】:how to open call making /dialing numer view open when button press?按下按钮时如何打开拨打/拨号号码视图?
【发布时间】:2011-07-09 09:07:23
【问题描述】:
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]; 

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

【问题讨论】:

    标签: ios objective-c uibutton phone-call


    【解决方案1】:

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

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

    【讨论】:

    • 您可以根据需要使用任何方法。如果手机号码是动态的,您可以将其保存在单独的变量中并使用 stringWithFormat: 方法附加它。
    • 哪个更好?在模拟器中任何一项工作。请编写正在使用的那一行代码。
    • 谢谢 Jim Thio,我现在已经添加了 ;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多