How to refresh the NSLocale in iPhone?

筅森魡賤 提交于 2019-12-12 14:44:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!