简体   繁体   English

将电话号码复制/粘贴到键盘中或以编程方式在iOS中拨打免费电话号码

[英]Copy/paste phone number into keypad or dial a toll free number in iOS programatically

I am trying to make a call from my app using 我正在尝试使用我的应用程序拨打电话

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://1800000002"]];

This is a toll free number in India.But while dialing, it is converting to +1(800)-000-000 (Converting and Saying dialing to United states number) 这是印度的免费电话号码。但拨号时,它转换为+1(800)-000-000(转换和说拨号到美国号码)

I have referred Copy/paste phone number into keypad And When I'm redialing a Toll free No. in India, iPhone is connecting USA ]. 我已经将复制/粘贴电话号码引用到键盘中当我在印度重拨免费电话时,iPhone正在连接美国 ]。 But could not find the solution. 但找不到解决方案。

So can any please help me to avoid this ISD call Indian local call.. 所以请任何请帮助我避免这个ISD电话印度本地电话..

The telprompt wants the number in the international format. telprompt想要国际格式的号码。 So you need to convert it to that. 所以你需要将它转换为它。 I think for India and the number you are trying to call, this should be +911800000002 . 认为对于印度和你要拨打的号码,这应该是+911800000002

So this should work: 所以这应该工作:

NSURL *phoneURL = [NSURL URLWithString:@"telprompt://+911800000002"];
if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {
    [[UIApplication sharedApplication] openURL:phoneURL];
} else {
    // handle that case. e.g show number to user so that they can
    // type it in a phone manually or copy it to the clipboard and
    // notify user about that.
}

Depending on how the local numbers compared to international format works in India, you might need to remove the 1 on your number, not sure about that. 根据本地数字与国际格式在印度的比较情况,您可能需要删除数字上的1 ,不确定。

On a sidenote: You should always use the international format when dealing with phone numbers. 旁注:在处理电话号码时,您应始终使用国际格式。 Otherwise a device that is currently outside of the destination country may call somebody else or simply can't place the call at all. 否则,目前在目的地国家/地区之外的设备可能会呼叫其他人或根本无法拨打该电话。

County code added (For India : +91) 县代码添加(印度:+91)

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://+911800000002"]];

Generic way to find out country code 找出国家代码的通用方法

NSLocale *currentLocale = [NSLocale currentLocale];  // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc.

Your app might get rejected by Apple if you use telprompt. 如果您使用telprompt,Apple可能会拒绝您的应用。 Use the following code to dial a number programmatically and see that you are inputting the number you'd like to call with correct format. 使用以下代码以编程方式拨打号码,并查看您是否输入了要以正确格式呼叫的号码。

NSString *phoneNumber = @"+1800000002;
NSString *phoneURLString = [NSString stringWithFormat:@"tel:%@", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];

source: Replacing tel or telprompt to call source: 替换tel或telprompt以进行呼叫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM