我有一个UIButton,上面有一个电话号码作为标题。
此代码是否会打开带有标题编号的手机应用?
- (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]];
}