I have several Text Field items in the Root.plist of my Settings.bundle. I need all of them for my app, but I want one of them to be either hidden or un-editable by the user. E.g. When the user goes on his iPhone to Settings-->MyApp, I want one of the fields to not be visible there, or disabled for editing. Is this possible?
Sure you can. Just change the item type to title.
You still can save and read it's value from code. but, it will not appear in the app. settings.
After further research I have found the answer to my question, and the answer to the problem I am trying to solve.
Question: Can you hide/disable fields in Settings.bundle/Root.plist?
Answer: No.
Problem: How do I securely store authentication information for my app?
Answer: Built in Keychain services.
Source: Keychain Services Tasks for iOS
Short answer, you can't. Long answer: I presume you are using the Root.plist somewhere else inside your app, is that right? If so, what I'd recommend in this case, if you really need it to work the way you described, is to create two plist files, and merge them at runtime.
In other words, create Root.plist with only the fields you want the user to change in the iOS settings page (e.g, without the field you are currently trying to hide), and another .plist file with the rest of the fields you want to handle inside your app.
Then, at runtime, you first load Root.plist, and then merge the contents of the another .plist file in the data structure you'll be using.
Not very slick, but could possible work.
Setting the type in the plist from "Text Field" to "Title" works in that you get a field that is no longer editable by the user but can be read by the app.
It doesn't look quite right in as far as UI consistency goes, so this may not be the ideal solution to disable a preferences item.
Related
I'm using Settings.bundle for few configuration settings for my app.
Now I'm searching for a solution to hide all, or even better, some configuration parts for the casual users. Only a 'admin' should see and edit these fields.
Is it possible to check for a password before showing the settings-properties?
If not, what could be a suitable solution? (new view controller with secret gesture or button?)
Thx in advance!
You won't be able to do anything special in the settings bundle. It's static, whatever you compile is what all users will see. If you want special behavior, there are two ways to do it:
Put it in the app itself and only allow the user access if they have the right credentials. A secret gesture could work too, but is a little dangerous because users may accidentally find out about it.
Use a different target/scheme or compile-time conditionals (using #if) to build two different versions of the app, one that does include the special configuration and one that doesn't. Personally, I would go for this option, but it may be a little harder initially.
It's been years since I've done iOS, but I'm jumping back into it and have a quick, beginners question. When the app launches, it will launch with a search field. You type in a persons name, hit enter, and info about the name will appear. I'm thinking about storing all the most common names in a plist, and having the search run through the plist after the user hits "enter", then display info about the name they typed in. This is where I'm stuck. After you type in the name and hit enter, I have no clue about how to make it display the info about the name, or even where to store data about the name. Any help is much appreciated, thanks!
I'll give you half of the answer you need here, the "loading" and "saving" part.
The "plist" you're talking about here is actually an array of names.
And -- how handy! -- "NSArray" has both an "initWithContentsOfURL:" method and a "writeToURL:atomically:" method.
Any more than just a few names and people will start suggesting using Core Data.
Also, if you want to be able to change and/or save the names while the app is running, you'll need to use a "NSMutableArray" instead of an immutable array.
As for the displaying part, you should probably learn how to use table views (UITableView) and binding (i.e. you "bind" to the array and values get displayed based on whatever the user typed into the search field). There are lots of tutorials and examples on this, as well as related questions here on StackOverflow.
Hi I want to create an application for the iPhone/ iPad, and on the initial page I want the user to have the option to change the language of the application (default language is English). Depending on the language the user chooses, for example Spanish, the initial page text and buttons will all be in Spanish. Then, after a button is pressed, the next view is also in Spanish. (And the back button is also in Spanish)
How could I do this? Remember, I DO NOT want to use Localization. Instead, I want the user to have to possibility to change the language of the app, WITHIN the same app, and NOT the Settings app.
Help with maybe a few examples would be very much appreciated.
Thank you very much in advance!
I've done this a few times. iOS is not designed for this and the first thing you should do is reconsider your approach or go back to the client and make absolutely sure it is necessary. There are only a few situations where this approach is the right one, it's mostly a mistake.
Your first issue is with localising string resources. NSBundle offers methods to load localised strings. Have a singleton class to manage which language you've currently got selected. When you change the language, it can load the en.lproj directory (or whichever language is selected) as a bundle. From that point, instead of using the usual macros to get localised string resources, use a method on your singleton to fetch them from the current bundle.
The same applies to images and other resources - your singleton knows which localisation bundle is in play, so ask it for the resources you need.
When you change language, tell your singleton, and your singleton can load the relevant bundle and post a notification so that your view controllers know to update themselves.
If you are lucky, your nibs layouts work independently of language without modification. This means you can set up a base view controller that others inherit from that has an outlet collection for localised interface elements. It should listen for the notification and walk the collection to update the necessary items.
If you are unlucky and different localisations need different layouts, you'll probably have to save state, get the relevant nib from your singleton, then reload everything and restore state.
You also have a problem that can't be entirely fixed - iOS will still think it's in the main system language. Where there is iOS-supplied content that is out of your control, it will be localised to the main system language. You can mitigate that a little by setting the user preference AppleLanguages to an array with a string containing the locale before the application is fully initialised (i.e. in main.c). However this can only change languages when the application is launched.
A possible implementation:
Use CoreData to create a table of localized strings
Store a Name/Key, language, and value.
You'll then want to build out a manager class to help you read the values. Using a singleton here would probably be a good approach. You could then do things like this:
[[LanguageManager] instance] getLocalizedString:#"mainView_title" forLang:#"en"];
Have you tried to checkout this article?
I see you are asking to NOT to use localization, but the only reason I figured out is because you'd like to change language at runtime.
That post then offers (and explains how to use) a custom utility class to meet your requirements leveraging part of the already existing localization functionalities of the SDK.
Hope that's going to be useful.
I'm working on a home automation project. Here's what I want to do:
The app starts and it'll have a button to load an XML file.
The XML will have information about the rooms in the house like "Living Room, Dining Room, Kitchen etc.". It'll also have information about the equipment, like "Home Theater, TV, Blu-Ray Player, etc. in this case with a relation with the room that they belong" and so on with IR, RS-232 cmds, etc.
I'll install this app in different houses, so I intend just to change the XML file as the house changes.
I intend to generate the UI from the information contained in the XML file. E.g. The house has only "Living Room and Dining Room". The tab bar will show only those two tabs.
So, my questions:
Will Apple reject my app?
Can my customers just download the app from the App Store, and change and load the XML file? I mean, there's a package in the .app file, is it possible to open it and change the .xml file inside it?
Is it possible to change the UI as the XML information changes?
EDIT: more questions:
#competent_tech is saying that dynamic generation of code isn't allowed, but I'll change the code within the .storyboard or .xib .nib files, isn't it?
About the Contacts: I think is a little bit different idea, because in the contacts app, e.g.: there are 10 fields to fill out, like first name, last name, e-mail, phone number, etc. As a user, if I don't fill out the e-mail field, it'll still be there anyway. My plan is kind of different:
The house has 2 equipments to control: - Tab bar with item 1 and item 2.
The house has 3 equipments to control: - Tab bar with item 1 and item 2 and item 3.
Do you still think this is possible?
Can you recommend a book about this? I couldn't find anything useful myself.
Unfortunately, only apple can answer the rejection question.
However, from what you have described, there shouldn't be an issue since this is configuration-based changes instead of code changes. Apple specifically prohibits download of code and dynamic generation of code.
You can liken it to Contacts: iOS doesn't come configured with contacts, they allow you add them and configure different things about them. This sounds very much like what you are doing.
You should be able to download an XML file from a website or web service and use that to configure the app. We use a web service to retrieve data into the local Sqlite database to configure nomenclature and UI component visibility based on the current user and it works quite nicely.
With generating code they mean executable code, not the generating of views or viewcontrollers. If that is forbidden too, you could distribute your app via addhoc, but you need one developer program per 99 clients.
I want to write an application that assigns Fogbugz cases programmatically, how would I accomplish this? Is it possible to achieve this given any of the following scenarios:
The user enters text in my
application's input field and the
Fogbugz report is opened in the
browser where the "note" field is
populated with the text from the user
input
The fogbugz report is assigned to the
specified user in the application
without the browser even being opened
i.e. the report is stored directly in
the DB.
I'm planning to add default values to the other fields as well so I would assume the process would be the same for adding text to the "note" field.
You can do this with the Fogbugz API. See the heading "Editing Cases" for the specifics on how to edit a case (which includes creating a new one). It's a little complicated (or perhaps just oddly designed) but, as I remember, you basically have to call cmd=new if you want to create a new case, supply your text in the 's' parameter and set the ixPersonAssignedTo to the correct person. For an existing case, use cmd=edit.
This is possible both with a regular form posted to your Fogbugz installation and some server side code that calls the API.
You might want to write a plugin for FB and allow others to use it. (share it or sell it)