Copy/paste phone number into keypad or dial a toll free number in iOS programatically
Asked Answered
D

3

9

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

Discompose answered 29/4, 2016 at 12:35 Comment(1)
pls re phrase your question . Looks like copy/paste is not what you want.Shrum
G
2

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.

Garth answered 12/5, 2016 at 7:8 Comment(8)
With your answer ,My loop executes in "if" part in loop which again exhibits same issueDiscompose
Did you try my comment with removing the 1? So use +91800000002? The problem you are having is not apple's API here, but that you need to know how the indian telephone numbering works according to international formats.Garth
@ Michael Ochs, Yes I have tried this. but gave me message yes "This is not a valid number"..Only turn off the Dail assist only saved but that is manually functionDiscompose
@sujania can you dial the number like this in your iPhone manually?Garth
For manual dialling , it is connecting to correct number without any format changeDiscompose
yes but you need to find the international number that works manually. (+91...). That's the number you need to put in there. I can't help you much with that as this is a local problem. In Germany our area codes all start with 0, our international code is +49 and when converting we skip the leading 0 of the area code. So e.g. local 0123456789 would be international +49123456789. Putting the latter in the NSURL works, no matter in which country the caller is in.Garth
@sujania This might help as well: countrycode.org/india Seems like toll free numbers in international format need to start with +91 080 in India.Garth
@ Michael Ochs, thank you for the link , but the call is redirecting to wrong number without using 1 or invalid number with appending +91Discompose
C
1

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.
Consumption answered 17/7, 2016 at 18:42 Comment(3)
thank you for post but Country code returns as "US" for me with your code which is supposed to ISO country code is: in and the above telprompt again redirects me to ISD numberDiscompose
Hi @Sujania you might be checking on simulator, because I checked it & on device it returns correct value !Consumption
,My requirement not to get the local country code , but to avoid calling toll free number as ISD when dial assist is on in user device phone settings. I am testing on iPhone5s Device onlyDiscompose
F
0

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

Feint answered 29/4, 2016 at 12:44 Comment(7)
this is giving same me error as I m getting currently .Discompose
If you want to be sure to get the Indian number, why not append +91? So @"+911800000002"Carangid
@Carangid If i add +91 , than it is giving me massage as not a valid numberDiscompose
You app can be rejected if you doesn't check opening url so: if ([[UIApplication sharedApplication] canOpenURL:phoneURL]) {..open url }Ypsilanti
@Sujania, I think this has to do "Dial Assist" feature. Go to Settings -> Phone -> Switch off Dial Assist and see if it now works with @"1800000002" (don't put a "+"). Unfortunately there's no way to tell whether your users have this option on or off. I would file a bug with Apple about this not being recognised properly by Dial Assist.Carangid
@Carangid thank you..Yes only with this it is giving a valid dail call..but trying for same functionality when fail assist is enabled also...Hope as you said me, this may not be possibleDiscompose
This answer is incorrect. a) why should this get rejected? Using telprompt for years! b) specifying +1 instead of 1... makes the 1 the international code, which points to the USA.Garth

© 2022 - 2024 — McMap. All rights reserved.