1

在我的代码中,我有这个片段可以用拨号前缀拨打电话(基本上是一个“打电话给我”按钮):

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

我想知道iPhone是否会在不需要时隐藏拨号前缀(?)。

谢谢,

4

2 回答 2

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.

于 2014-08-15T09:37:24.257 回答
0

对于那些感兴趣的人,我找到了一种简单的方法,使用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"]];
    }
}

效果很好。

于 2014-08-15T07:37:02.443 回答