获取当前国家时出错 [英] Error in getting current country
本文介绍了获取当前国家时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码获取当前国家/地区
I am using following code to get current country
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCodes = [locale objectForKey:NSLocaleCountryCode];
NSString *countryName = [locale displayNameForKey:NSLocaleCountryCode value:countryCodes];
NSLog(@"%@",countryName);
我在阿联酋,但这是显示美国,我在我的iPod上测试,请帮助如何我可以获得当前国家吗?
I am in UAE , but this is showing United States , I testing on my iPod , please help how Can I get current country ?
推荐答案
-(void)viewWillAppear:(BOOL)animated
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[super viewWillAppear:animated];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
NSLog(@"Detail is:--> %@",placemark);
NSString *strCountry = [NSString stringWithFormat:@"Current Cuntry %@",[placemark.addressDictionary objectForKey:@"Country"]];
NSLog(@"label detail is:--> %@",strCountry);
lblAddress.text = strCountry;
}
试试此代码......这肯定会为您提供当前的国家/地区详细信息。
Try this code...This will definately give you a current country detail.
这篇关于获取当前国家时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文