Find current country from iPhone device

前端 未结 9 880
醉话见心
醉话见心 2020-12-04 08:38

I have to get the current country in the iPhone settings. Can anyone tell me how to get the current country in iPhone application.

I have to use the current country

相关标签:
9条回答
  • 2020-12-04 09:02
    NSTimeZone *gmt = [NSTimeZone localTimeZone];
    
    NSLog(@"timezone gmt %@",gmt.abbreviation);
    
    0 讨论(0)
  • 2020-12-04 09:03

    If you're testing and want to use a different language from your system, it's easiest to change your scheme's Application Language and Application Region options instead of changing the language and region on your device or simulator.

    Go to Product->Scheme->Edit Scheme...->Run->Options and choose the Application Language and Application Region you want to test.

    From the iOS Documentation: Testing Your Internationalized App

    0 讨论(0)
  • 2020-12-04 09:04

    Swift 3.0 solution

    if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
                print(countryCode)
            }
    
    0 讨论(0)
  • 2020-12-04 09:06

    For Swift 4.0,

    You can simply use

    let countryCode = Locale.current.regionCode

    print(countryCode)

    0 讨论(0)
  • 2020-12-04 09:10
    NSLocale *locale = [NSLocale currentLocale];
    NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
    NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
    
    0 讨论(0)
  • 2020-12-04 09:14

    For devices with SIM card you can use this:

      CTTelephonyNetworkInfo * network_Info = [CTTelephonyNetworkInfo new];
      CTCarrier * carrier = network_Info.subscriberCellularProvider;
      NSString  * countryCode = [carrier.isoCountryCode uppercaseString];
    
    0 讨论(0)
提交回复
热议问题