NSLocale *local = [NSLocale currentLocale];
if (![local.currencyCode isEqualToString:@"CNY"]) {}// 地區貨幣代碼。注意,currencyCode只能在iOS 10及以上的版本可使用,因此低於這個版本的系統上,會crash。git
能夠用下面的判斷:ide
// 當前所在地信息,包括語言與地區spa
NSString *identifier = [[NSLocale currentLocale] localeIdentifier];3d
NSString *displayName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier];orm
if (![displayName isEqualToString:@"中文(中國)"]) {}// 只有地區是中國,語言是簡體中文,displayName纔是@"中文(中國)"
ci
// 當前所在地的使用語言it
NSLocale *currentLocale = [NSLocale currentLocale];class
NSLog(@"Language Code is %@", [currentLocale objectForKey:NSLocaleLanguageCode]);object
// 系統語言im
NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
NSString *strLang = [arLanguages objectAtIndex:0];
語言是簡體中文:
2017-09-18 10:50:23.517 CeShi[2343:854583] 中文(中國)
2017-09-18 10:50:23.521 CeShi[2343:854583] LanguageCode is zh
2017-09-18 10:50:23.521 CeShi[2343:854583] AppleLanguages:zh-Hans-CN
語言是English:
2017-09-18 11:08:51.587 CeShi[2396:860809] English (China)
2017-09-18 11:08:51.589 CeShi[2396:860809] LanguageCode is en
2017-09-18 11:08:51.589 CeShi[2396:860809] AppleLanguages:en-CN
// 輸入框,對金額格式化
_invalidInputCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];//NSCharacterSet
_currencyNumberFormatter = [[NSNumberFormatter alloc] init];//NSNumberFormatter
_currencyNumberFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];// 無論手機的地區和語言是什麼,直接初始化成 中國和簡體中文;
_currencyNumberFormatter.numberStyle = kCFNumberFormatterCurrencyStyle;
_currencyNumberFormatter.usesGroupingSeparator = YES;