Recently, I started to learn the development process and ideas of complete IOS project. In the actual project development process, we usually need to version control and manage the project code and data. Generally, SVN or GitHub is commonly used for code version control and project management. Xcode, the development tool of our IOS project, has integrated GitHub’s code control, so it will be more convenient to use GitHub. If you want to know the specific operation steps of Xcode and GitHub link, you can stamp here: IOS learning – xcode9 upload project to GitHub.
After creating a project, before we develop code for a project, we need to build the development environment of IOS project. Our application name, project name, application icon and startup image are all set in this step. Therefore, this part is the basis of the whole project development, and there are often some settings needed in the subsequent development process Use the steps here to make changes. But at present, the information found on the Internet is very short and scattered, so today we hope to have a detailed understanding and study of all kinds of details of building IOS project on Xcode.
I. difference between project and targets
First of all, the development environment of IOS project is mainly based on our project and targets. So, what are these two things? When we click on our project name, the interface shown in the following figure will appear. As can be seen from the picture, there are two parts of project and targets shown in blue and red boxes on the right panel of project navigation panel.
What exactly do project and targets mean? The simple explanation is as follows:
Project: a project is a repository of all files, resources, information / configurations. A project contains all the content needed 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 its build setting, which will override the default build setting of the project, which will be discussed later). Target: in short, target defines the compilation settings of the project and determines the compilation order of various resources and codes in the project. Each target only depends on one project, but there can be multiple targets in a project. There are two targets (klbaisi and klbaisitest) shown in the above figure. Each target has different settings, but there is only one active target at the same time. We can choose which target to compile with. The specific operation selection is shown in the figure below. A target and its product can be associated with other targets. If a target build needs the “output” of another target, it can be said that the first target depends on the second. 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 explicit target dependencies for two targets in build setting. For example, you might build a library and an application (the same workspace) that links the library. Xcode can find this relationship and automatically build the library first. However, if you want to link to a version of library instead of one build in the workspace, you can create a certain dependency in build settings that will override implicit dependency.
2. The property setting of project and target
As for the property setting of project and target, the following figure shows the property setting interface of project and target. On the left is the property setting interface of project, and the right is the attribute setting interface of target. Relatively speaking, the project is relatively simple, only info and build setting. After all, it is only a simple setting of project resources, while the setting of target is relatively complex, including 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 app. Let’s learn and understand the function of the settings of each interface.
2.1 project property setting
The property setting of project has two parts: info and build setting. However, there is a correlation between the build setting of project and the build setting of target. Part of the setting of build setting of target will inherit the part of build setting of project. Therefore, the build setting part of the project is explained in the 2.2target property setting section. This section is mainly about the information property setting part of the project. The interface of the info property is as follows:
It is mainly divided into three parts: deployment target, configurations and localizations.
Deployment target: deployment configuration is mainly used to configure the minimum running version of the app generated by this project. By default, it is the latest version of the API on Xcode. Therefore, we need to set here where we need to adapt the lower version in our project. Similarly, we can set this property in build setting, and the two are synchronized. Localizations: localization. The main function here is to add the languages supported by our app. Through the [+] [-] button in the red circle at the bottom of the above figure, you can add or delete different languages, and you can choose to adapt different languages according to the settings of the mobile phone. For the bottom choice, whether to enable internationalization, it is enabled by default
Configurations: the xcconfig file used to configure IOS projects. It is mainly used to compile in several different development environments. Xconfig file is actually the config file in Xcode, which is used to save the key value pairs of build settingsPlain text file。 These key value pairs override the values in build settings, so when the options are configured in the xcconfig file, the settings in build settings will not work. We usually do not customize xcconfig file in the project. The specific xconfig file is what things, you can see: IOS xconfig gossip. It is estimated that many new IOS developers are not very familiar with xcconfig files (in fact, I don’t know much about it either.) However, you may have used cocoapods. In fact, most of the project configuration management of cocoapods depends on xcconfig file. Therefore, in a project that uses cocoapods to import packages, by opening the. Xcworkspace file, we will find that there are corresponding configuration files under Project > info > configurations. However, there are no relevant configuration files for those that were not configured with cocoapods. The specific differences are shown in the following figure.
2.2 target attribute setting
As I mentioned earlier, there are quite a lot of content about setting the attribute of target. There are seven items in total: general, capabilities, resource tags, info, build setting, build phases and build rules. Next, we’ll learn about and learn about them one by one.
2.2.1 setting the general attribute of target
The general attribute setting interface of target is shown in the figure below, which is mainly divided into six parts. Let’s explain the meaning of each part.
The identify column mainly defines some identity attributes related to application release.
Display name: the name of the app installed on the IOS phone or iPad.
The bundle identifier is the unique ID of the application, which is used to identify the operating system and the Appstore. In the process of creating a project or object, Xcode creates its own package identifier. In general, do not modify it. Version is the version number that users can see.
Build (build number) is the version number that developers see themselves to distinguish between internal test versions. Signing is mainly used for certificate management. When debugging or packaging, we need to sign for authentication. Here is a simple use of the tutorial, you can stamp here if you need: IOS automatically sign function, directly on the device packaging.
Deployment info defines some identity properties related to application configuration.
Deployment target: used to set the minimum supported version. This is the same as the meaning in “info” of the project. Moreover, the settings of the two should be the same. If not, the final app will be subject to the setting of target.
Devices: used to set up supported devices. There are three options: iPhone, iPad and universal.
Main interface: the main interface view preloaded at application startup. There are two ways to do it Main.storyboard To set up this method, we need the logic and jump of the whole project to be in Main.storyboard The main interface can be started by canceling the stroryboard in. Instead, the main. M method is used to start the interface, and the – (bool) application: (uiapplication *) application in appdelegate is also implemented Didfinishlaunchingwithoptions: (nsdictionary *) launchoptions “method, specify the main interface view to start. This method is used in general projects because there are many interfaces in general projects, and many of them are defined in the style of pure code, so that it is convenient to modify and locate problems, and the logic of the project is clearer, especially for projects with multi person cooperation, this style is more suitable.
Device orientation: defines the direction the application supports. There are several directions, such as portrait, upside down, landscape left (horizontal review, home key on the left), and landscape right. Status bar style app icons and launch images: app icons and launch pages. There are three main settings: application icon, startup image and startup page. See the official website: human interface guidelines for the size and size of specific application icons and startup pages.
App icon source: corresponds to the file resource Assets.xcassets The images in appicon in the directory are shown in the following figure. The right most panel allows you to select which or several devices to add icons. The size of icons on each model of device is different. In the middle there are a small grid, we will all cut the icon directly drag over, they will automatically find their place in the grid. These small lattices are mainly divided into four categories: notification: the icon for notification. Similar to the application related push message, sometimes the icon of this application will display this size Spotlight: search for small icons. When you enter the application name in spotlight, the icon of the application will appear in the search results, and the icon in the settings will be of this size. App: This is the normal app icon. The app displayed on the desktop after installation, or when sharing recommendations, is also an icon of this size. App Store: the icon displayed in the app store, luanch image Source: also corresponding to the file resource Assets.xcassets The images in luanchimage in the directory set the startup images under various conditions, and the specific interface will not be taken. Like appicon, we drag all the cut icons directly, and they will automatically find the grid they should put in. The startup image actually defines the size of the interface after the application is started, so we need to do a good job of adaptation in different models. See the role of the startup page in screen adaptation below. An app must set the startup image of the corresponding device, otherwise clicking on the app will be a piece of black and white.
Luanch screen file: it is a storyboard file with the same function as luanch image, but the priority of the startup file is higher than that of the startup image. In other words, if both are set, the startup page is based on the startup file. If neither is set, the startup page cannot be started. The function of the startup page: when we click the application icon to start the application, the application startup needs a certain operation time. During the restart period, in order to enhance the user experience of the application startup, you should provide a startup image. The startup image looks very similar to the first screen of the application. When the user clicks on your app icon on the home screen, the iPhone OS will immediately display the startup image. Once you’re ready, your application will display its first screen to replace the bootstrap image. It must be emphasized that the reason why the startup image is provided is to improve the user experience, not to provide: application entry experience “, such as startup animation.
The role of the startup page in screen adaptation: each model, such as a program that supports both iPhone and iPad, needs to specify a startup image for iPhone and iPad respectively. When the old iPhone 4 program runs on the iPhone 5, and there is no iPhone 5 startup image, it adopts compatibility mode with black edges on the top and bottom. When a new startup image is specified for the iPhone 5, the system assumes that the app is already compatible with the iPhone 5. When the old iPhone 5 program runs on the iPhone 6, if not adapted. The old program is automatically scaled up and covered with new mobile phones, and the old program can also run normally. This scheme can be regarded as automatic adaptation. But because the old program stretched, the overall look a bit virtual, also can’t make better use of the large screen space. When the developer needs to manually adapt, just like iPhone 4 to iPhone 5, specify a new startup image in the new app. When the startup map is specified, the system thinks that the application has completed the screen adaptation, and the screen resolution becomes the size it should be. On a certain model, if it is auto adapted, such as the iPhone 5, the old version will have two more black bars on the upper and lower ends of the screen; for example, the iPhone 6 / 6 plus will automatically stretch the old version of the program. How to turn off auto adaptation? Specify the startup diagram or use launch screen File.xib In other words, the program uses manual adaptation, and will not stretch. However, the program must have been processed internally, otherwise the automatic adaptation scheme will be used. Embedded binaries: used to connect binaries, usually when using third-party SDK. Linked frameworks and libraries: select the framework and library to be linked. It can be either a framework from the SDK or a third-party framework. There are similar function options in build phases.
2.2.1 setting the info attribute of target
The info attribute setting interface of target is shown in the figure below, which is mainly divided into five parts. We will interpret the meaning of each part.
In this part, the most important part is the first part custom IOS target properties, custom IOS target properties. The other four parts are basically useless, so we can just ignore it. In the info tab of target, the five items of information in our project resource directory info.plist The contents of the file are consistent, and modifying one of them will automatically change the other. In addition, some of the settings in the General tab we talked about in 2.2.1 also correspond to info.plist In the file, so these contents are interlinked. If we modify one place, other places will be modified at the same time. info.plist In fact, there will be a lot of loading information. The above are some of the most basic setting options automatically generated after the project is created. The corresponding meaning of each item is explained as follows:
Localization native development region: related to localization settings, it is the default development language. Executable file: the name of the program installation package bundle identifier: the unique identification of the software, which is automatically generated according to the company’s identity and project name. Infodictionary version: version information bundle is used when uploading and testing Name: the name displayed after app installation bundle OS type code: used to identify the package type bundle versions string, short: the released version string bundle creator OS type code: the ID of the creator bundle version: application version numberapplication requirements iPhone environment: used to indicate whether the package can only run on the iPhone OS System. The default is yes Launch screen interface file base name: the file name of the welcome interface
In addition, we may need to add some other information in the development process, including the addition of some permissions, network permissions, location permissions, read-write contact permissions, etc. the addition of application whitelist is configured here. about info.plist Please refer to Xcode for details Info.plist Field list details.
The other four parts are simply explained
Document types: defines the document types recognized by the application, and can also define the custom icon of this type of document displayed in the system. Exported UTIs export UTI: UTI uniform type identifiers. Imported UTI: URL types URL type: used to define the URL so that the application can understand the data structure exchanged between applications. Can be used to: IOS wake up other programs, programs call each other. For example: in urltypes, set up AAPP in urlschemes; in B program, OpenURL: [nsurl urlwithstring: @ “AAPP:”]; note that the “:” colon cannot wake up another program without a colon. Secondly, if there is a “&” special character in the parameter, it is recommended to base 64 transform the parameter.
2.2.3 capabilities attribute setting of target
Target’s capabilities attribute setting is mainly used to select some performance setting switches, such as push notification, cloud storage, game center, background mode, etc. we select the required switch to turn on or off, and these corresponding states will be in the info.plist To modify. So, in the same way, we can also info.plist After adding some permissions or performance switches, the corresponding changes will be made in the capabilities of target. The specific interface is shown in the following figure:
2.2.4 resource tag attribute setting in target
The resource tag tab in target is mainly used to add tag classification for the resources in the project, so that we can align the loading sequence and loading time for selection and setting, that is, load on demand, and load resources only when needed. The attribute setting interface is shown in the figure below. The advantage of this method is that the following resource loading forms can be realized:
Delayed loading of initial resources: the app has some resources that are needed by the main functions, but they are not needed at startup. Mark these resources as initial needs. The operating system will automatically download these resources when the app starts. For example, the image editing app has many filters that are not commonly used. Delayed loading of APP resources: app has some resources that are only used in specific scenarios. When the application may 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: the app has some resources that are rarely used and will be requested when they are needed. For example, when the app opens for the first time, it shows a tutorial that may not be used later. The app requests the resources of the tutorial when it starts for the first time. After that, it only requests the resources after the tutorial needs to be displayed or new functions are added. Remote storage of in app purchase resources: app provides in app purchase with additional resources. After the purchase of the app module is completed. For example, a user purchases the supergeeky emoticon pack in a keyboard app. The application requests the resources of the emoticon pack after the startup is complete. Loading of necessary resources at the first startup: some resources of the app are only needed at the first startup, and are no longer needed after startup. For example, the app has a tutorial that is only shown at first startup.
For details on resource tag and on-demand loading, please refer to the following two articles:
Chinese version of on demand resources guide
Chinese version of on demand resources guide
2.2.5 set the build setting property 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 figure below. The interface is only a part of it. The complete build settings has 20 configuration contents. From the configuration interface, each configuration has four columns. We can see that the order from left to right is: resolved column, column with target icon, column with project icon and IOS default column. The meaning of each column is as follows.
Resolved column: the final compilation method cannot be set by itself. The result is to determine the compilation method adopted in the final compilation according to the selection results of the three columns on the right and the priority order. By selecting the combined option in the second row tab of the graph, you can directly see the final result with only this column. Column with target icon: the compilation options of build setting configuration of target can be customized. It has the highest priority. Once set, the final compilation method is based on the result of this column. Column with project Icon: the compilation options of the build setting configuration of the project can be customized. The results of this column are consistent with those in the build setting tab of the project. If you modify one place, another will be automatically modified. Its priority is between target and default. When target does not set compilation options and this column is set, the final compilation method is based on this column. IOS default column: the default compilation option provided by the system when creating a project, which cannot be modified. The priority is the lowest. Only when the other two columns are not set with options, the final compilation method will be based on this column. Priority order: column with target icon > > column with project icon > > column with IOS default.
Each line in the build setting tab of target represents the compilation details in Xcode compilation options.
2.2.6 setting the build phase property of target
The main function of the build phase tab of target is to configure the compiler parameters in different compilation stages, including the required resource files (including code, configuration and various resource files). The configuration interface is shown in the figure below, which mainly includes four aspects.
Target dependencies target object dependency stage: some targets may depend on the output value of a target. The dependency is set here. When relying on the output of other targets, the system will automatically compile the dependent target at compile time, get the output value, and then compile the current target. The object dependency phase allows Xcode to know other dependent objects (such as application extensions, plug-ins, etc.) that must be compiled for the currently selected object. This stage cannot be deleted. Compile sources source file compilation stage: it refers to which source code will be compiled. You can add or delete resources through the [+] [-] button in the red box to control the compiled code file. And you can modify the compiler flags of the modification phase to set the compiler weaving for each individual file, such as optimization settings, etc. Link binary with libraries: refers to which library files will be referenced during the compilation process. We can also add or delete the library files referred to in the compilation process through the [+] [-] button. Copy bundle resources: refers to which resource files will be included in the. App of the generated product. You can also add or delete resources through the [+] [-] button in the red box to control the compiled resource files. This stage defines the resource files in the object, including application, icon, interface builder, video, template, etc. These resources will be copied to the contents / Resources folder of the installation package.
2.2.7 set the build rules property of target
I haven’t contacted and set the build rules of target at ordinary times. I haven’t found any information after searching the Internet for a long time. If you have relevant information, please leave it in the comments and I can add it up.