NSLocale and country name

后端 未结 2 1147
天命终不由人
天命终不由人 2020-12-07 18:34

I used this code for getting which country iPhone belong to:

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLoc         


        
2条回答
  •  旧巷少年郎
    2020-12-07 19:34

    Query an english locale for the displayName

    like this:

    NSLocale *locale = [NSLocale currentLocale];
    NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
    
    NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    
    NSString *country = [usLocale displayNameForKey: NSLocaleCountryCode value: countryCode];
    

提交回复
热议问题