- 创建您的应用内购买可用的国家/地区列表。
- 将该列表转换为区域设置标识符的 NSArray。
- 遍历该数组并创建一个 NSLocale
- 使用此语言环境创建带有 NSNumberFormatter 的价格字符串
- 保存您使用过的所有字符。
- ???
- 利润
这样的事情应该这样做:
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
nf.numberStyle = NSNumberFormatterCurrencyStyle;
NSMutableSet *set = [NSMutableSet set];
// all available locales, you probably don't need them all
NSArray *availableLocaleIdentifiers = [NSLocale availableLocaleIdentifiers];
// compile a list of the locales you'll need
availableLocaleIdentifiers = @[ @"de_DE", @"de_CH", @"en_GB", @"en_US", @"ja_JP"];
for (NSString *localeIdentifier in availableLocaleIdentifiers) {
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier];
nf.locale = locale;
NSString *priceString = [nf stringFromNumber:@(123456789.99)];
for (NSInteger i = 0; i < [priceString length]; i++) {
unichar character = [priceString characterAtIndex:i];
[set addObject:[NSString stringWithFormat: @"%C", character]];
}
}
NSArray *sorted = [set sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES]]];
NSString *allCharacters = [sorted componentsJoinedByString:@""];
NSLog(@"\"%@\"", allCharacters);
输出:"$',.0123456789CFH £€¥"