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
NSTimeZone *gmt = [NSTimeZone localTimeZone];
NSLog(@"timezone gmt %@",gmt.abbreviation);
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
Swift 3.0 solution
if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
print(countryCode)
}
For Swift 4.0,
You can simply use
let countryCode = Locale.current.regionCode
print(countryCode)
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
For devices with SIM card you can use this:
CTTelephonyNetworkInfo * network_Info = [CTTelephonyNetworkInfo new];
CTCarrier * carrier = network_Info.subscriberCellularProvider;
NSString * countryCode = [carrier.isoCountryCode uppercaseString];