Andrew f0s3 Kosenko
Andrew f0s3 Kosenko

Reputation: 25

Objective-C iOS App: Is there a storage that allows me to save a key-value pair data that will be available between my app restarts?

I'm writing a feature of the language change. First screen of the app I'm writing is about setting the language. When he user presses the button, my app directs user to app settings. I expect user to set some language and show it to them as soon as they go back to my app.

But as soon as I click on some language option, my app xcode console says: Message from debugger: Terminated due to signal 9

Additionally, as soon as I return to my app, it gets loaded as if I closed and reopened it.

I thought that maybe I can have some code that will set a global variables like "currentLanguage" and "previousLanguage" and if those are different - I will load localisation files for "currentLanguage" and will start downloading localised videos from my server.

Upvotes: 0

Views: 245

Answers (1)

ArtFeel
ArtFeel

Reputation: 11801

System terminate your app when user change language in Settings. So you can use NSUserDefaults for persistent storage and compare this values on app start, to detect if language was changed.

Example:

NSString *currentLanguage = [[NSLocale preferredLanguages] firstObject];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject: currentLanguage forKey:@"previousLanguage"];
NSString *previousLanguage = [userDefaults objectForKey:"previousLanguage"];

Upvotes: 1

Related Questions