在 iOS 中使用按钮呼叫电话号码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6101286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:03:47  来源:igfitidea点击:

Making a Button Call a Phone Number in iOS

iosiphonecocoa-touchphone-call

提问by Sam

I want to create a button that, when pressed, will call a phone number on the iPhone. I don't know if this is possible, but if it is I'd love for someone to help me with this.
I dont have any code for it, so someone would need to help me from start to finish.

我想创建一个按钮,当按下该按钮时,将拨打 iPhone 上的电话号码。我不知道这是否可行,但如果可行,我希望有人能帮助我解决这个问题。
我没有任何代码,所以有人需要从头到尾帮助我。

回答by arclight

Try this out in your button action

在您的按钮操作中试试这个

-(IBAction)callPhone:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1115550123"]];
}

Then in Interface Builder you should connect the TouchUpInsideevent to the previously declared action (callPhone:) and you are done.

然后在 Interface Builder 中,您应该将TouchUpInside事件连接到先前声明的操作 ( callPhone:) 并完成。

回答by Yossi Tsafar

You can also go back to your original app when finish the call just by using this one instead:

您还可以在结束通话时返回到您的原始应用,只需使用此应用即可:

-(IBAction)callPhone:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://2135554321"]];
}

Enjoy!

享受!