Change currency symbol based on county dynamically

2019-05-30 06:53发布

I want to change the currency symbols in iPhone app based on user's localization. If my app is working in US i need to change the currency symbol "$". If the app is working in Eroupe countries, we need to change the symbol to "€", if the app is in Japan, the symbol should be change to "¥" and if the app is running in Australia the symbol should be in "$". By this way if the app is running in any country the app should be change the currency sign based on the localizations. I have used this below code but, it always shows in "$". How can i solve this? And also how can i test this? Please help me.

NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"Amount with symbol: %@", [currencyFormat stringFromNumber:@"10.00"]); 

Please help me. Where i am wrong? Thanks in advance.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-05-30 07:11

The simulator has support for changing localizations, just like on a regular device. Make sure that you change that before starting your app and it should show the correct format.

To change the locale (on the simulator):
Start the simulator (by starting your app), press the Home button, go to Settings, General, International and then choose the Region Format you want to test. Close the simulator after it's done and restart your app. The locale has changed so you should see that in the currency symbol that is shown.

On real devices you follow the same route to change the locale.

查看更多
登录 后发表回答