Question

Am getting the device local currency symbol by using this code.

 NSLocale *theLocale = [NSLocale currentLocale];
 NSString *symbol = [theLocale objectForKey:NSLocaleCurrencySymbol];
 NSLog(@"Symbol : %@",symbol);
 NSString *code = [theLocale objectForKey:NSLocaleCurrencyCode];
 NSLog(@"Code : %@",code);

When the app restart the currency symbol changing but when the app from background the currency symbol not updating.

  1. In iPhone setting i have changed the region United States and launched the app the currency symbol show "$".
  2. When i have change the region India and get the app from Background and call the same code it shows again "$". The currency symbol not updating. When i came back and reenter into the screen the currency symbol updating to India symbol.

In appDelegate:

- (void)applicationWillEnterForeground:(UIApplication *)application:

[[NSNotificationCenter defaultCenter] postNotificationName:@"CurrencyUpdated" object:nil];

In sampleViewController: viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadCurrencySymbol) name:@"CurrencyUpdated" object:nil];

In sampleViewController:

-(void) reloadCurrencySymbol
{
    NSLocale *theLocale = [NSLocale currentLocale];
    NSString *symbol = [theLocale objectForKey:NSLocaleCurrencySymbol];
    NSLog(@"Symbol : %@",symbol);
    NSString *code = [theLocale objectForKey:NSLocaleCurrencyCode];
    NSLog(@"Code : %@",code);
}

Can anyone please help to solve this issue? Thanks in advance.

EDIT

I have recalled the [self viewDidLoad]; but the region has not changed. When i return to previous screen and again enter into the same screen the region is updating. Can anyone please help to solve this? Thanks.

Was it helpful?

Solution

in your sampleview controller add this in viewdidLoad

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadCurrencySymbol) name: UIApplicationDidBecomeActiveNotification object:nil];

this is the right way to reload your symbol when the app becomes active

OTHER TIPS

Likely its similar to MacOSX where when you change the language you need to restart the app to get it to start with the new locale.

I'm guessing that you would need to quit first, and there's probably no other way around it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top