简体   繁体   中英

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)

I have referred Copy/paste phone number into keypad And When I'm redialing a Toll free No. in India, iPhone is connecting USA ]. But could not find the solution.

So can any please help me to avoid this ISD call Indian local call..

The telprompt wants the number in the international format. So you need to convert it to that. I think for India and the number you are trying to call, this should be +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.

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)

 [[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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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