使用按钮和文本字段/视图打开电话(呼叫)(iPhone)

发布于 2024-10-15 04:42:15 字数 149 浏览 2 评论 0原文

这可能吗?

该应用程序将有一个按钮和一个文本字段或文本视图。

用户在文本字段或文本视图中输入电话号码。当用户完成后,用户按下按钮,这将打开“电话”按钮并拨打该号码。

我该怎么做?如果可以请提供一些代码! :)

先感谢您!

Would this be possible?

The app will have a button and a Text Field or a Text View.

The user types in the phone number in the Text Field or Text View. when the user is done the user presses the button which will open the Phone button and place the call to the number.

How would I do this? If possible please provide some code! :)

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

べ映画 2024-10-22 04:42:15

看看这段代码,这应该可以正常工作!

-(IBAction)newuser:(id)sender;
{
    NSString *URLString = [@"tel://" stringByAppendingString:textfield.text];

    NSURL *URL = [NSURL URLWithString:URLString];

    [[UIApplication sharedApplication] openURL:URL];
}

Take a look at this code, This should work fine!

-(IBAction)newuser:(id)sender;
{
    NSString *URLString = [@"tel://" stringByAppendingString:textfield.text];

    NSURL *URL = [NSURL URLWithString:URLString];

    [[UIApplication sharedApplication] openURL:URL];
}
牵强ㄟ 2024-10-22 04:42:15

您可以将电话号码格式化为 tel:// URL。因此,如果您有一个文本字段(出于我们的目的,MyTextField):

NSString *URLString = [@"tel://" stringByAppendingString:MyTextField.text];

NSURL *URL = [NSURL URLWithString:URLString];

[[UIApplication sharedApplication] openURL:URL];

You can format a phone number as a tel:// URL. So, if you have a text field (MyTextField for our purposes here):

NSString *URLString = [@"tel://" stringByAppendingString:MyTextField.text];

NSURL *URL = [NSURL URLWithString:URLString];

[[UIApplication sharedApplication] openURL:URL];
风筝有风,海豚有海 2024-10-22 04:42:15

iPhone 支持 tel: URI 方案,如 RFC 3966 所定义。因此,一个要求电话拨打号码“12345”的简单示例是:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12345"]];

这应该会导致设备切换到正常的电话应用程序并拨打该号码。您需要验证文本字段以检查非法输入;该规范实际上允许使用相当多的字符(请参阅第 5 页的正式语法),但作为第一个测试,您可能需要删除任何不是数字的内容。

The iPhone supports the tel: URI scheme, as defined by RFC 3966. So a simple example that would ask that the phone call the number '12345' would be:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12345"]];

That should cause the device to switch over to the normal Phone application and dial the number. You'll want to validate the text field to check for illegal entries; the spec actually allows quite a few characters (see the formal grammar on page 5), but as a first test you might want to remove anything that isn't a number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文