0

我正在使用以下代码获取当前国家

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCodes = [locale objectForKey:NSLocaleCountryCode];
NSString *countryName = [locale displayNameForKey:NSLocaleCountryCode value:countryCodes];
NSLog(@"%@",countryName);

我在阿联酋,但这显示的是美国,我在我的 iPod 上进行测试,请帮助我如何获得当前国家/地区?

4

1 回答 1

2
-(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;
}

试试这个代码......这肯定会为您提供当前国家/地区的详细信息。

于 2012-07-26T07:19:48.773 回答