Ios 使用按钮标题打开手机应用程序

Ios 使用按钮标题打开手机应用程序,ios,uibutton,openurl,Ios,Uibutton,Openurl,我有一个标题是电话号码的按钮 此代码是否会打开带有标题号的手机应用程序 - (IBAction)callContact:(id)sender { [[UIApplication sharedApplication] openURL: [NSURL URLWithString:telfButton.titleLabel.text]]; } 它给了我一个错误。取决于URL是什么。 如果它只是3033749943它就不会工作。但是tel://3033749943可以正常工

我有一个标题是电话号码的按钮

此代码是否会打开带有标题号的手机应用程序

- (IBAction)callContact:(id)sender 
{
    [[UIApplication sharedApplication] openURL: 
        [NSURL URLWithString:telfButton.titleLabel.text]];
}
它给了我一个错误。

取决于URL是什么。
如果它只是
3033749943
它就不会工作。但是
tel://3033749943
可以正常工作。

如另一个答案中所述,您必须使用“tel://”启动手机应用程序并拨打电话号码。但是,您可以使用
NSString
stringWithFormat
在按钮标题中的“tel://”之后添加数字

- (IBAction)callContact:(id)sender 
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",telfButton.titleLabel.text]];
}