In iOS, the Foundation framework provides the low-level mechanism for storing the preference data. Apps then have two options for presenting preferences:
ไฟล์ List ทรัพย์สินหรือที่รู้จักกันทั่วไปว่าเป็นไฟล์ plist มีพื้นโปรแกรมประยุกต์ของ Mac แฟ้มการกำหนดลักษณะเฉพาะ พวกเขามีข้อมูลและการตั้งค่า. Working with Property List Files -Property List Editor.app -Creating a Property List from Scratch with Property List Editor -Command-Line Utilities -Cocoa for Scripters -Altering.plist Files in Memory -Summary -Resources -Chapter 5 Writing a Property List for Management.
Which option you choose depends on how you expect users to interact with preferences. The Settings bundle is generally the preferred mechanism for displaying preferences. However, games and other apps that contain configuration options or other frequently accessed preferences might want to present them inside the app instead. Regardless of how you present them, you use the
NSUserDefaults class to access preference values from your code.
This chapter focuses on the creation of a Settings bundle for your app. A Settings bundle contains files that describe the structure and presentation style of your preferences. The Settings app uses this information to create an entry for your app and to display your custom preference pages.
For guidelines on how to manage and present settings and configuration options, see iOS Human Interface Guidelines.
The Settings App Interface
The Settings app implements a hierarchical set of pages for navigating app preferences. The main page of the Settings app lists the system and third-party apps whose preferences can be customized. Selecting a third-party app takes the user to the preferences for that app.
Every app with a Settings bundle has at least one page of preferences, referred to as the main page. If your app has only a few preferences, the main page may be the only one you need. If the number of preferences gets too large to fit on the main page, however, you can create child pages that link off the main page or other child pages. There is no specific limit to the number of child pages you can create, but you should strive to keep your preferences as simple and easy to navigate as possible.
The contents of each page consists of one or more controls that you configure. Table 4-1 lists the types of controls supported by the Settings app and describes how you might use each type. The table also lists the raw key name stored in the configuration files of your Settings bundle.
![]()
For detailed information about the format of each preference type, see Settings Application Schema Reference. To learn how to create and edit Settings page files, see Creating and Modifying the Settings Bundle.
The Settings Bundle
A Settings bundle has the name
Settings.bundle and resides in the top-level directory of your app’s bundle. This bundle contains one or more Settings page files that describe the individual pages of preferences. It may also include other support files needed to display your preferences, such as images or localized strings. Table 4-2 lists the contents of a typical Settings bundle.
In addition to the Settings bundle, the app bundle can contain a custom icon for your app settings. The Settings app displays the icon you provide next to the entry for your app preferences. For information about app icons and how you specify them, see App Programming Guide for iOS.
When the Settings app launches, it checks each custom app for the presence of a Settings bundle. For each custom bundle it finds, it loads that bundle and displays the corresponding app’s name and icon in the Settings main page. When the user taps the row belonging to your app, Settings loads the
Root.plist Settings page file for your Settings bundle and uses that file to build your app’s main page of preferences.
In addition to loading your bundle’s
Root.plist Settings page file, the Settings app also loads any language-specific resources for that file, as needed. Each Settings page file can have an associated .strings file containing localized values for any user-visible strings. As it prepares your preferences for display, the Settings app looks for string resources in the user’s preferred language and substitutes them in your preferences page prior to display.
The Settings Page File Format
Each Settings page file is stored in the iPhone Settings property-list file format, which is a structured file format. The simplest way to edit Settings page files is to use the built-in editor facilities of Xcode; see Preparing the Settings Page for Editing. You can also edit property-list files using the Property List Editor app that comes with the Xcode tools.
Note: Xcode converts any XML-based property files in your project to binary format when building your app. This conversion saves space and is done for you automatically.
The root element of each Settings page file contains the keys listed in Table 4-3. Only one key is actually required, but it is recommended that you include both of them.
Hierarchical Preferences
If you plan to organize your preferences hierarchically, each page you define must have its own separate
.plist file. Each .plist file contains the set of preferences displayed only on that page. Your app’s main preferences page is always stored in a file called Root.plist . Additional pages can be given any name you like.
![]()
To specify a link between a parent page and a child page, you include a child pane control in the parent page. A child pane control creates a row that, when tapped, displays a new page of settings. The
File key of the child pane control identifies the name of the .plist file with the contents of the child page. The Title key identifies the title of the child page; this title is also used as the text of the control used to display the child page. The Settings app automatically provides navigation controls on the child page to allow the user to navigate back to the parent page.
Figure 4-1 shows how this hierarchical set of pages works. The left side of the figure shows the
.plist files, and the right side shows the relationships between the corresponding pages.
For more information about child pane controls and their associated keys, see Settings Application Schema Reference.
Localized Resources
Because preferences contain user-visible strings, you should provide localized versions of those strings with your Settings bundle. Each page of preferences can have an associated
.strings file for each localization supported by your bundle. When the Settings app encounters a key that supports localization, it checks the appropriately localized .strings file for a matching key. If it finds one, it displays the value associated with that key.
When looking for localized resources such as
.strings files, the Settings app follows the same rules that other iOS apps follow. It first tries to find a localized version of the resource that matches the user’s preferred language setting. If no such resource exists, an appropriate fallback language is selected.
For information about the format of strings files, language-specific project directories, and how language-specific resources are retrieved from bundles, see Internationalization and Localization Guide.
Creating and Modifying the Settings Bundle
Xcode provides a template for adding a Settings bundle to your current project. The default Settings bundle contains a
Root.plist file and a default language directory for storing any localized resources. You can expand this bundle as needed to include additional property list files and resources needed by your Settings bundle.
Adding the Settings Bundle
To add a Settings bundle to your Xcode project:
In addition to adding a new Settings bundle to your project, Xcode automatically adds that bundle to the Copy Bundle Resources build phase of your app target. Thus, all you have to do is modify the property list files of your Settings bundle and add any needed resources.
The new Settings bundle has the following structure:
Preparing the Settings Page for Editing
Before editing any of the property-list files in your Settings bundle, you should configure the Xcode editor to format the contents of those files as iPhone settings. Xcode does this automatically for the
Root.plist file, but you may need to format additional property-list files manually. To format a file as iPhone Settings, do the following:
Configuring a Settings Page: A Tutorial
This section shows you how to configure a Settings page to display the controls you want. The goal of the tutorial is to create a page like the one in Figure 4-3. If you have not yet created a Settings bundle for your project, you should do so as described in Adding the Settings Bundle before proceeding with these steps.
Creating Additional Settings Page Files
The Settings Bundle template includes the
Root.plist file, which defines your app’s top Settings page. To define additional Settings pages, you must add additional property list files to your Settings bundle.
Macos Property List Editor
To add a property list file to your Settings bundle in Xcode, do the following:
Mac Property List Editor
After adding a new Settings page to your Settings bundle, you can edit the page’s contents as described in Configuring a Settings Page: A Tutorial. To display the settings for your page, you must reference it from a child pane control as described in Hierarchical Preferences.
Best Video Editor Mac
Note: In Xcode 4, adding a property-list file to your project does not automatically associate it with your Settings bundle. You must use the Finder to move any additional property-list files into your Settings bundle.
Debugging Preferences for Simulated Apps
When running your app, iOS Simulator stores any preferences values for your app in
~/Library/Application Support/iOS Simulator/User/Applications/ <APP_ID>/Library/Preferences , where <APP_ID> is a programmatically generated directory name that iOS uses to identify your app.
Each time you build your app, Xcode preserves your app preferences and other relevant library files. If you want to remove the current preferences for testing purposes, you can delete the app from Simulator or choose Reset Contents and Settings from the iOS Simulator menu.
Property List Editor For MacProperty List Editor.app
Copyright © 2013 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2013-10-22
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |