Question

I am currently working in iPhone application, Using NSLocale to get the current Currency symbol working fine, but when i press home button the app goes to background process and i change the Currency (Setting>>International>>Regionformat>>Like United states,India etc...) in this way, then open that application from background the currency symbol not changed, but i navigate to another screen then comes to previous screen only currency changed, but i want when i open the application from background, then currency symbol changed automatically. How to fix this? I need your help

Thanks

I tried code here:

NSLocale *theLocale = [NSLocale currentLocale];
Getdollarsymbol = [theLocale objectForKey:NSLocaleCurrencySymbol];
NSString *Code = [theLocale objectForKey:NSLocaleCurrencyCode];
Était-ce utile?

La solution

Please try this code. And let me know if this is working,

In -viewDidLoad: Add Line:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshCurrencySymbol) name:NSCurrentLocaleDidChangeNotification object:nil];

then:

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

Thanks.

Autres conseils

What about the following:

[NSLocale autoupdatingCurrentLocale]

Apple docs mentions

The object always reflects the current state of the current user's locale settings.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top