1

In my code, I have this snippet to make a phone call with dialing prefix (basically, a "call me" button) :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://+0000000000"]];
if(SYSTEM_VERSION_LESS_THAN(@"7.0")) {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:+0000000000"]];
}

I wonder if the iPhone will hide the dialing prefix when it's unnecessary (?).

Thanks,

Till
  • 27,559
  • 13
  • 88
  • 122
Camille S.
  • 61
  • 1
  • 6

2 Answers2

0

For those interested, I found a easy way, using NSLocale currentLocale:

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

if ([countryCode isEqualToString:@"FR"]){
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://0000000000"]];
}
else {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://+33000000000"]];
}

if(SYSTEM_VERSION_LESS_THAN(@"7.0")) {
    if ([countryCode isEqualToString:@"FR"]){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://0000000000"]];
    }
    else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:+ 33000000000"]];
    }
}

Works deliciously.

Till
  • 27,559
  • 13
  • 88
  • 122
Camille S.
  • 61
  • 1
  • 6
  • This is not perfectly correct. I may reside in any country but choose to use french locale for numbers and dates. – Desdenova Aug 15 '14 at 08:00
  • Hi Desdenova, if you know a better way, I'm aware ! Perhaps with use of "CTTelephonyNetworkInfo" ? – Camille S. Aug 15 '14 at 08:17
  • I'm not sure. I don't think that `CTCarrier` will change when roaming. Why not leave `+ 33`for all cases? It will still call when you are in France. – Desdenova Aug 15 '14 at 08:24
  • I thought too that leaving +33 still call from France. I am currently in France and I just did a test. It's not working... – Camille S. Aug 15 '14 at 08:35
  • What do you think if I do : if ([carrier.mobileCountryCode isEqualToString:@"208"]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://0000000000"]]; } else { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://+33000000000"]]; } – Camille S. Aug 15 '14 at 09:05
  • 1
    I think carrier.mobileCountryCode doesn't change when roaming when user is abroad. I think carrier.mobileCountryCode depends of SIM card inserted. Correct me if I'm wrong, I'm not sure. – Camille S. Aug 15 '14 at 09:08
0

Second answer to my own question :

according to this post, mobile Country code doesn't change when roaming : Does CTCarrier mobileNetworkCode change when roaming?

Best way is therefore :

{

CTTelephonyNetworkInfo *info = [CTTelephonyNetworkInfo new];

CTCarrier *carrier = info.subscriberCellularProvider;

NSLog(@"country code is: %@", carrier.mobileCountryCode);
// Get mobile network code



if ([carrier.mobileCountryCode isEqualToString:@"208"]){
    [[UIApplication sharedApplication]
     openURL:[NSURL URLWithString:@"telprompt://0000000000"]];
}

   else {
    [[UIApplication sharedApplication]
     openURL:[NSURL URLWithString:@"telprompt://+33000000000"]];
}


    if(SYSTEM_VERSION_LESS_THAN(@"7.0")) {
        if ([carrier.mobileCountryCode isEqualToString:@"208"]){
            [[UIApplication sharedApplication]
             openURL:[NSURL URLWithString:@"tel://0000000000"]];
        }
        else {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:+33000000000"]];
        }
}
}

Works fine too.

Community
  • 1
  • 1
Camille S.
  • 61
  • 1
  • 6