【问题标题】:How to get country code according to current location?如何根据当前位置获取国家代码?
【发布时间】:2013-10-19 02:38:03
【问题描述】:

我有获取国家代码的代码。但我想要印度的 +91 之类的国家代码。如何获得?

NSArray *countryCodes = [NSLocale ISOCountryCodes];     
NSMutableArray *countries = [NSMutableArray arrayWithCapacity:[countryCodes count]];
for (NSString *countryCode in [NSLocale ISOCountryCodes])  {    
    NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];
    NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier];
    [countries addObject: country];
}

NSDictionary *codeForCountryDictionary = [[NSDictionary alloc] initWithObjects:countryCodes forKeys:countries];

NSLog(@”%@”,codeForCountryDictionary);

【问题讨论】:

    标签: iphone ios ipad core-location


    【解决方案1】:

    您可以为此目的使用 CoreTelephony 框架。在你的项目中包含这个框架

    CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];
    CTCarrier *carrier = network_Info.subscriberCellularProvider;
    NSString *countryCode = carrier.mobileCountryCode
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-11
      • 2015-12-29
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多