Initiate phone call from app with area code (prefix)

480 Views Asked by At

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,

2

There are 2 best solutions below

0
On

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.

6
On

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.