在 iOS 应用程序中拨打电话
我有一些代码尝试在应用程序中拨打电话,但它似乎不起作用:
UIApplication *myApp = [UIApplication sharedApplication];
NSString *theCall = [NSString stringWithFormat:@"tel://%@",phone];
NSLog(@"making call with %@",theCall);
[myApp openURL:[NSURL URLWithString:theCall]];
有时,变量 phone
类似于 @"(102) 222-第2222章如何使用这样的电话号码拨打电话?我是否需要手动从中提取数字并删除所有多余的标点符号?
I have some code which attempts to make a call within an application, but it doesn't seem to be working:
UIApplication *myApp = [UIApplication sharedApplication];
NSString *theCall = [NSString stringWithFormat:@"tel://%@",phone];
NSLog(@"making call with %@",theCall);
[myApp openURL:[NSURL URLWithString:theCall]];
Sometimes, the variable phone
is something such as @"(102) 222-2222"
. How can I make a call with a phone number like this? Do I need to manually extract the numbers out of it and get rid of all the extra punctuation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。你需要自己把它们拿出来。或者您可以使用下面的代码片段...
注意:您可能会想使用
-stringByTrimmingCharactersInSet:
,但是该方法仅删除字符串开头和结尾的字符,而不是如果它们出现在中间。Yup. You need to take those out yourself. Or you can use the snippet below...
Note: you may be tempted to use
-stringByTrimmingCharactersInSet:
, but that one only removes characters at the start and the end of the string, not if they appear in the middle.要返回原始应用程序,您可以使用 telprompt:// 而不是 tel:// - 告诉提示将首先提示用户,但当通话完成后,它将返回您的应用程序:
只是对上述答案的更新。
To go back to original app you can use telprompt:// instead of tel:// - The tell prompt will prompt the user first, but when the call is finished it will go back to your app:
just an update on above answer.
这是一个简单的方法,可用于拨打电话并在通话结束后返回到应用程序。
将以下内容添加到您的 .m 文件中
然后在您想要进行调用的任意位置添加以下代码:
Here's a simple method that can be used to make a call and return to the app after the call is finished.
Add the following to your .m file
Then add the following code wherever you want to make the call from: