Sam*_*mar 3 iphone currency refresh ios nslocale
我目前正在使用iPhone应用程序,使用NSLocale使当前的货币符号正常工作,但是当我按下主页按钮时,应用程序进入后台进程并更改货币(设置>>国际>> Regionformat >>像美国,印度等...)以这种方式,然后从背景打开该应用程序货币符号没有改变,但我导航到另一个屏幕然后来到前一个屏幕只有货币改变,但我想当我从背景打开应用程序,然后货币符号自动更改.如何解决这个问题?我需要你的帮助
谢谢
我试过这里的代码:
NSLocale *theLocale = [NSLocale currentLocale];
Getdollarsymbol = [theLocale objectForKey:NSLocaleCurrencySymbol];
NSString *Code = [theLocale objectForKey:NSLocaleCurrencyCode];
Run Code Online (Sandbox Code Playgroud)
请试试这段代码.让我知道这是否有效,
在-viewDidLoad:添加行中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshCurrencySymbol) name:NSCurrentLocaleDidChangeNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
然后:
-(void) refreshCurrencySymbol
{
NSLocale *theLocale = [NSLocale currentLocale];
NSString *symbol = [theLocale objectForKey:NSLocaleCurrencySymbol];
NSLog(@"Symbol : %@",symbol);
NSString *code = [theLocale objectForKey:NSLocaleCurrencyCode];
NSLog(@"Code : %@",code);
}
Run Code Online (Sandbox Code Playgroud)
谢谢.