In desktop applications when talking about a config file sometimes it's about letting the end client change some parameters according to his systems - for example entering his system IP or other parameters that can not be hardcoded, and must change by him because the user doesn't want you to know them.
I read about the option to create a settings.plist and reaching the value from NSBundle but how can the end client change the values in it?
You're talking about implementing a settings bundle. Once you've done that, the user will be able to adjust the values in the main iOS Settings app - there will be a section for your app.
There are many Preference control types available. You can use a Text field.
The text field type displays a title (optional) and an editable text field. You can use this type for preferences that require the user to specify a custom string value.
The key for this type is PSTextFieldSpecifier.
To retrieve the edited value at run time, use the below code.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *iPAdress = [defaults objectForKey:#"IP address"];
Once these all done, Go To your iPad default Setting App-> You can view your application name listed under Apps section. Tap on it.
Related
having trouble with Logic App usage, so i am receiving a file with example text below and need to map them according to their tags. so for each tag they will go to different fields in my database. Keep in mind I cannot change the structure of the file, stays as is due to previous systems:
:2e:hello
:3t:there
:fy:people
What I do is pull the file from file storage and them i can access the content which are the values above. But what I need to do is check if i have ':2e:' and if so take its value which is 'there'.
Any suggestions?
thanks
I have been going through the process of localizing my apps and in doing so I temporarily set the language to Chinese like this:
ApplicationLanguages.PrimaryLanguageOverride = "zh-CN";
However, after commenting out the line and rebuilding / re-deploying, now my app is still stuck in Chinese instead of what my development machine's default language at the OS level (English)!
How do I reset this to go back to the default OS setting?
Just assign an empty string to the PrimaryLanguageOverride property :
ApplicationLanguages.PrimaryLanguageOverride = string.Empty;
The PrimaryLanguageOverride setting is persisted between sessions. It
should not be set each time the app is loaded. It should only be set
based on user input presented in settings UI. The property can be read
at any time. If the property has never been set, it returns an empty
string.
So if you set the property to an empty string, the app will use the default language.
I'm using the Settings bundle for an iOS application. Is it possible to add some constraints to a field based on another field?
I give an example. I have two fields:
Field1: 10;
Field2: 15;
It is possible to force the user to put into 'Field2' a value that is smaller than 'Field1' ?
Thank you
No, validation logic like that can't be included in the settings bundle. It is a purely static/declarative form of defining the structure of the settings. However, you can of course validate and sanitize the properties at the point where you read them from NSUserDefaults in your app.
Here's the scenario. I have a set of settings in an app. For example consider my app as a video player. So there are settings like allow full screen, display subtitles etc. All these settings have boolean values since you either turn on or off them.
These settings should display inside the app in a table view. And if any of them are activated or when the user taps on them to activate/deactivate, you show it by setting the checkmark accessory view of that cell.
Since I need the settings to be displayed this way and only within the app, I cannot simply use Settings bundles. There's also another catch. I need these settings to be localized.
What I initially thought was to have separate plists for the languages I support.
Settings_en.plist (English)
Settings_sv.plist (Swedish)
Then fetch the plist name depending on the system language and display its values.
let filePath = NSBundle.mainBundle().bundlePath.stringByAppendingPathComponent(NSLocalizedString("SETTINGS_PLIST", comment: ""))
But this is not ideal because say I'm running in Swedish and I change the Subtitles setting to on. Now i have to update this in both plists. This will quickly become even messier if I add more languages in the future.
Is there a better way to store settings which is easier to save and fetch and also supports localization?
I was able to find an answer elsewhere. Here are the steps taken to resolve this issue.
Instead of multiple plists, create one plist and have the keys in English language.
Then have the localized strings in your string files with the same English keys.
Localizable.strings (English)
FULL_SCREEN = "Full Screen";
SUBTITLES = "Subtitles";
Localizable.strings (Swedish)
FULL_SCREEN = "Helskärm";
SUBTITLES = "Undertexter";
In the code when you're displaying the values in a table view, refer to them by that key.
let setting = settings[indexPath.row] as [String: Bool]
let title = setting.keys.first
cell.textLabel?.text = NSLocalizedString(title!, comment: "")
How can one possibly display an information paragraph within settings.app? I'd use root.plist and NSUserDefaults group footer. But how can I link these two together, so the information can be modified dynamically from the app?
I would like to display information like: #"Your secret user code is: %d", userCode. And change the userCode every time the user e.g. purchases something.