IOS learning-detailed configuration of iOS Project and Targets, iostargets
I recently started to learn the development process and ideas of the complete iOS project. In the actual project development process, we usually need to control and manage the version of the project code and materials, generally, SVN or Github is commonly used for code version control and project management. Xcode, the development tool of our iOS project, was originally integrated with the code control of Github, so it is more convenient to use GitHub. If you want to learn more about the specific operation steps of Xcode and GitHub links, you can click here:IOS learning-upload a project to GitHub in Xcode9.
After creating a project, we need to set up the development environment of the iOS project before developing code for a project, the Application name, project name, application icon, and startup image are all set in this step. Therefore, this part is the basis for the entire project development, in the subsequent development process, some settings are often used here for modification. However, the information found on the Internet is very short and fragmented. Therefore, we hope to have a detailed understanding and learning about the various details of the iOS project on Xcode.
Difference between Project 1 and Targets
First, the iOS Project's development environment is mainly built based on the Project and Targets of our Project. So what are these two things? Click the project name, and the page shown is displayed. You can see from the picture that there are two sections on the right panel of the PROJECT navigation panel: PROJECT and TARGETS in the blue and red boxes.
What does PROJECT and TARGETS mean? The explanation on the official website is as follows:Xcode Concept. If you see English, you will have a headache:IOS: [translation] Xcode Concepts-concept Target, Project, Build Setting, Workspace, Scheme. A simple explanation is as follows:
- Project: project is the repository of all files, resources, information/configurations. A project contains all the content required to build your products and maintains the relationship between them. It can contain multiple targets. A project defines the default build setting for all targets (each target can customize their build setting. These custom setting will overwrite the default build setting of the project, ).
- Target: in short, target defines the project compilation settings and determines the compilation sequence of various resources and codes in the project. Each target depends on only one project, but one project can have multiple targets, and the two targets shown are (KLBaiSi and KLBaiSiTest). Each setting is different, however, there is only one active Target at a time. During compilation, we can select which target to compile. The specific operation options are shown in.
- A Target and its product can be associated with other targets. If a Target build requires the "output" of another target, it can be said that the first target depends on the second target. If the two targets are in the same workspace, Xcode will find their dependencies and build the products in a specific order. This relationship is called "implicit dependency." You can also specify a clear target dependency for the two targets in build setting. For example, you may build a library and an application linked to the library (the same workspace ). Xcode can discover this relationship and automatically build this library first. However, if you want to link a version of the library instead of one built in the workspace, you can create a definite dependency in build settings, which will overwrite implicit dependency.
Attribute settings for project 2 and target
For the attribute settings of project and target, see the attribute settings page of project and target. The attribute settings page of project on the left is displayed, and the attribute setting page of target is displayed on the right. Relatively speaking, the project is relatively simple. There are only info and build setting items. After all, it is simple to set the project resources, while the target setting is complicated, there are seven items: general, capabilities, resource tags, info, build setting, build phases, and build rules, because each setting of target directly determines the Display Effect of our final App. Next we will learn and understand the functions of the settings on each interface.
2.1 project attribute settings
The property settings of a project include info and build setting. However, the build setting of a project is related to the build setting of target, A part of the build setting settings of target will inherit the build setting section of the project. Therefore, the build setting section of the project is explained in the 2.2target attribute setting section. This section mainly describes the info attribute setting section of the project. The info attribute interface is as follows:
There are three main parts:Deployment Target, deployments, and Localizations.
- Deployment Target: Deployment configuration, which is mainly used to configure the lowest version that can be run for the App generated for this project. The default version is the latest version of the API on Xcode. Therefore, in our project, we need to set the lower version adaptation here. Similarly, we can set this attribute in build setting. The two are synchronous.
- Localizations: Localization. The main function here is to add languages supported by our App. You can add or delete different languages through the "+" [-] button in the bottom red circle, you can also choose to adapt to different languages based on the phone settings. The following options are enabled by default. For details about how to enable internationalization and adaptation of different languages, see: iOS Internationalization
- Deployments: Used to configure the xcconfig file of the iOS project. It is mainly used for compiling in several sets of different development environments. The xcconfig file is actually the config file in xcode. In essence, it is used to save the Build Settings key-value pair.Plain text file. These key-value pairs overwrite the values in Build Settings, soWhen the options are configured in the xcconfig file, the Settings in Build Settings will not work.. We generally do not customize the xcconfig file in the project. For details about the xcconfig file, refer to the Xcconfig discussion on iOS. It is estimated that many new iOS developers are not very familiar with xcconfig files (in fact, I am not very familiar with xcconfig files ...), But you may have used Cocoapods. In fact, many Cocoapods project configuration management relies on the xcconfig file. So in the project that uses Cocoapods for package import, we open it. in the xcworkspace file, we will find that all the corresponding configuration files under project --> info --> configutations are available, but there is no relevant configuration file for the original configuration without Cocoapods, as shown in the specific differences.
2.2 target attribute settings
As I mentioned earlier, target has many attribute settings.General, capabilities, resource tags, info, build setting, build phases and build rulesSeven items. Next we will learn and understand them one by one.
2.2.1 general attribute settings of target
The general attribute setting interface of target is shown in. It consists of six parts. The following describes the meaning of each part of the settings.
- IdentifyThe identifier column mainly defines some identity attributes related to application Publishing.
- Display Name: the Name of the App installed on iOS or iPad.
- Bundle Identifier is the unique ID of the application. It is used to identify the operating system and AppStore. Xcode creates its own package identifier when creating a project or object. Generally, do not modify it.
- Version (external Version number) allows you to see the Version number.
- Build (internal version) the version number that the developer sees to distinguish the internal test version.
- Signing(Signature) is mainly used for Certificate Management. When debugging or packaging a real machine, we need to sign for authentication. Here is a simple tutorial. If you need it, you can stamp it here:IOS's Automatically Sign function is directly packaged on the device.
- Deployment Info(Deployment information) defines some identity attributes related to application configuration.
- Deployment Target: used to set the supported minimum version. This is one of the meanings in info of the project, and the two settings should be the same. If they are different, the final App will refer to the setting of target.
- Devices (device): it is used to set supported Devices. It has three options: iPhone, iPad, and Universal.
- Main Interface: the Main Interface view preloaded when the application is started. There are two methods:
- One is to use Main. storyboard for startup. To set this method, we need to complete the logic and redirection of the entire project in Main. storyboard.
- Cancel the stroryboard method to start the main interface, but run main in code mode. the m method is started and started by specifying the main interface view in the AppDelegate-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions method.This method is generally used in projects, because there are many interfaces in the project, many of which are defined by the Code-only style, so that you can easily modify and locate problems, the project logic is clearer, especially for projects with multi-person cooperation. This style is more suitable.
- Device Orientation: defines the direction supported by the application. There are Portrait, Upside Down, Landscape Left (horizontal evaluation, Home key on the Left), and Landscape Right.
- Status Bar Style)
- App Icons and Launch Images: Application icon and launch page. Three main settings: application icon, startup image, and startup page. For details about the application icons and startup page sizes, refer to the official website:Human Interface Guidelines.
- App icon Source: corresponds to the image in AppIcon in the file resource Assets. xcassets directory, as shown in. On the rightmost panel, you can select which devices or devices you want to add. the icons of each model have different sizes. There are small grids in the middle. we drag all the cut icons and they will automatically find the grids they should put in. These small grids are mainly divided into four types:
- Notification: the icon used for Notification. For example, if an application-related push message is displayed, the icon of this application is displayed.
- Spotlight: small search icon. When you enter the app name in Spotlight, the app icon displayed in the search result is of this size, and the icon in the settings is of this size.
- App: this is the normal App icon. The App displayed on the desktop after installation, or the App displayed during recommendation sharing, is also the icon of this size.
- App store: the icon displayed in the App store
- Luanch Image Source: corresponds to the file resource Assets. the pictures in the LuanchImage in the xcassets directory are set to start pictures in various circumstances. The specific interface is not available. Like Appicon, we drag all the cut icons directly, they will automatically find the grid they should put in.The startup image actually defines the page size after the application is started.Therefore, we need to adapt to different models. For details, see [the function of the startup page in screen adaptation] below ]. An App must set the startup image of the corresponding device. Otherwise, clicking the App will be black and white.
- Luanch Screen File (startup page File): a storyboard File,The role is the same as that of Luanch Image, but the priority of the Startup File is higher than that of the startup Image. That is to say, if both are set, the startup page is subject to the Startup File. If neither is set, the startup fails..
- The role of the launch page: When we click the application icon to start the application, it takes some time to start the application. During the restart period, in order to enhance the user experience when the application is started, you should provide a boot image. The startup image looks very similar to the app's first screen. When a user clicks your application icon on the home screen, the iPhone OS immediately displays the startup image. Once you are ready, your application will display its first screen to replace this startup placeholder image. It must be emphasized that the purpose of providing boot images is to improve the user experience, not to provide: Application entry Experience ", such as starting an animation.
- The function of the startup page in screen adaptation: for each model, for example, to support both iPhone and iPad programs, you need to specify the boot image for the iPhone and iPad respectively. When the old iPhone 4 program runs on the iPhone 5 without the startup image of the iPhone 5, it adopts the compatible mode and leaves black edges on and off. When a new boot image is specified for the iPhone 5, the system determines that the application is adapted to the iPhone 5. When the old iPhone 5 program runs on the iPhone 6, if it is not adapted. The old program automatically scales up and fills up new mobile phones, and the old program can run normally. This solution is automatically adapted. However, because the old program is stretched, the whole process looks a little virtual and cannot make better use of the screen space. When developers need to manually adapt, specify a new startup image in the new program, just like the transition from iPhone 4 to iPhone 5. When a startup image is specified, the system determines that the application has adapted the screen, and the screen resolution changes to the desired size. On a certain model,For automatic adaptation, for example, iPhone 5, the old version of the program will have two more black bars on the screen and the lower side; for example, iPhone 6/6 plus, the old version of the program will automatically perform proportional stretching.. How can I disable automatic adaptation? Specify the startup graph or use Launch Screen File. xib, that is, the program uses manual adaptation, and does not stretch, but the program must be processed internally. Otherwise, the automatic adaptation scheme is used.
- Embedded Binaries(Bind a binary file): used to connect a binary file. It is generally used when a third-party SDK is used.
- Linked Frameworks and Libraries(Linked frameworks and libraries): select the frameworks and libraries to be linked. They can be both SDK-built frameworks or third-party frameworks. Similar function options are available in Build Phases.
2.2.1 set the info attribute of target
The info attribute setting interface of target is shown in. It consists of five parts. The setting meaning of each part of our team is explained below.
In this part, the most important thing is the first part of the Custom iOS Target Properties Custom iOS Target attributes. The other four attributes are basically not very useful, so you don't have to worry about them. The five items in the info tab of target are the same as those in the info. plist file under the Resource Directory of our project, and the modification of one item is automatically modified. In addition, some settings in the general tab we mentioned in 2.2.1 also correspond to info. in plist files, the content is the same. We modify one place, and the other places will be modified synchronously. Info. plist actually loads a lot of information. The above are some of the most basic setting options automatically generated after the project is created. The meaning of each item is explained as follows:
- Localization native development region: it is related to Localization settings and is the default development language.
- Executable file: name of the program installation package
- Bundle identifier: the unique identifier of the software. It is automatically generated based on the company ID and project name. It is used during upload and test.
- InfoDictionary version: version Information
- Bundle name: name displayed after App Installation
- Bundle OS Type code: used to identify the Software Package Type
- Bundle versions string, short: released version string
- Bundle creator OS Type code: ID of the creator
- Bundle version: application version
- Application requires iPhone environment: Used to indicate whether the package can only run on the iPhone OS. The default value is YES.
- Launch screen interface file base name: name of the file on the welcome page
- Main storyboard file base name: the Main entry of the program by default
- Supported interface orientations: set the direction Supported by the program by default
In addition, we may need to add other information during the development process, including adding some permissions, network permissions, locating permissions, and read/write contact permissions, the application whitelist is configured here. For details about info. plist, see:List of Info. plist fields in Xcode.
A brief explanation of the other four parts:
- Document Types Document type: defines the Types of documents that can be recognized by applications, and can also define custom icons for such Types of documents displayed in the system.
- The UTIs: UTI Uniform Type Identifiers Exported by Exported UTIs has the same Type identifier.
- Imported UTIs:
- URL Types URL type: used to define a URL so that the application can understand the data structure exchanged between applications. It can be used for IOS to wake up other programs and call each other. For example: In URLTypes, the AAPP in URLSchemes; in program B, openUrl: [NSURL urlWithString: @ "AAPP:"]; note: "colon, you cannot wake up another program without a colon. If the parameter contains "&" special characters, base64 conversion is recommended.
2.2.3 set the capabilities attribute of target
Target's capabilities attribute settings mainly include some performance setting options, such as push notifications, cloud storage, game center, background mode, etc. We select the required switch to turn on or off, the corresponding status will be in info. in plist. Therefore, we can also add some permissions or performance switches in info. plist, and modify the permissions in capabilities of target. Shows the specific interface:
2.2.4 Resource Tag attribute setting in target
The Resource Tag tab in target mainly adds tag categories for resources in the project, so that we can select and set the Loading Order and loading time in order to load resources as needed, the resource is loaded only when necessary. The attribute setting interface is shown in. The advantage is that the following resource loading modes can be implemented:
- Delayed loading of initial resources: some resources of the app are required for main functions, but are not required at startup. Mark these resources as "initial needs ". The operating system automatically downloads these resources when the app starts. For example, the image editing app has many uncommon filters.
- Delayed loading of app resources: the app has some resources that are only used in specific scenarios. When the application may want to enter these scenarios, it will request these resources. For example, in a game with many levels, users only need the resources of the current level and the next level.
- Remote Storage of infrequently used resources: apps have a few resources that are rarely used and will request these resources when needed. For example, a tutorial is displayed when the app is opened for the first time, which may not be used after the tutorial. The app requests the resources of the tutorial When it is started for the first time. After that, you only need to display the tutorial or add a new function to request the resource.
- Remote Storage of purchased resources within an app: the app provides in-app purchase with additional resources. After the app is started, it requests resources of the purchased modules. For example, a user buys a SuperGeeky table package in a keyboard app. After the application is started, it requests the resources of the table package.
- Resource loading is required for the first startup: some resources of the app are only required for the first startup and are not required for subsequent startup. For example, the app has a tutorial that is only displayed at the first startup.
For more information about Resource Tag and On-Demand Loading, see the following two articles:
2.2.5 set the build setting attribute of target
The build setting tab of target is the most important part of the compilation option settings. The configuration interface is shown in. The interface is only part of it. The complete build settings contains 20 configuration items. From the configuration page, each configuration item has four columns. We can see that the order from left to right is: the Resolved column, the Target icon column, the Project icon column, and the iOS Default column represent the following meanings.
- Resolved Column:The final compilation method cannot be set by yourselfThe result is to determine the final compilation method based on the selection results in the three columns on the right and the priority order. Select the combined option on the second line tab of the graph. Only the final result of this column is displayed.
- Icon column with Target:Build setting configuration compilation options of target, which can be customized. It has the highest priority. Once set, the final compilation method is based on the result of this column.
- Project icon Column:Project build setting configuration compilation options, which can be customizedThe results in this column are the same as those in the build setting tab of the project. modify one of them and the other one automatically. Its priority is between target and default. When the target does not set the compilation option and this column is set, the final compilation method is subject to this column.
- IOS Default Column:The default compilation option provided by the system during project creation cannot be modified.. It has the lowest priority. The final compilation method is subject to this field only when no option is set for the other two columns.
- Priority Order: with Target icon column> with Project icon column> iOS Default Column.
For details about the compilation represented by each line in the build setting tab of target, see:Xcode compilation options.
2.2.6 set the build phase attribute of target
The main function of the build phase tab of target is to configure the parameters of the compiler in different compilation stages, including the required resource files for compilation (including code, configuration, and various resource files). The configuration interface is shown in, it mainly includes four aspects.
- Target Dependencies TargetObject dependency stage: some targets may depend on the output value of a Target. Here, dependencies are set. When it depends on the output of other targets, the system will automatically compile the target to be depended upon during compilation to obtain the output value and then compile the current target. The object dependency phase allows Xcode to know other dependent objects (such as Application Extensions and plug-ins) That must be compiled for the currently selected objects ). This stage cannot be deleted.
- Compile SourcesSource File compilation phase:It refers to the source code to be compiled. You can use the "+" [-] button in the red box to add or delete resources to control the compiled code file. In addition, you can modify the Compiler Flags (Compiler identifier) in the modification phase to set the Compiler knitting for each individual file, such as optimization settings.
- Link Binary With LibrariesLink to the binary library stage: it refers to the library files that will be referenced during the compilation process. We can also add or delete the library files referenced by the compilation through the [+] [-] button.
- Copy Bundle ResourcesCopy resource file stage: refers to the generated product. which resource files will be included in the app can also be added or deleted through the + button in the red box to control the compiled resource files. This stage defines resource files in objects, including applications, icons, interface constructors, videos, templates, and so on. These Resources will be copied to the Contents/Resources folder of the installation package.
2.2.7 set the build rules attribute of target
The build rules section of target has never been used or configured. I have not found any information on the Internet for half a day. If you have any related information, leave it in your comments. I can add it.