问题
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];
回答1:
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.
回答2:
What about the following:
[NSLocale autoupdatingCurrentLocale]
Apple docs mentions
The object always reflects the current state of the current user's locale settings.
来源:https://stackoverflow.com/questions/11614299/how-to-refresh-the-nslocale-in-iphone