IOS uses scripts to batch pack channel packages and ios script channel packages

Source: Internet
Author: User

IOS uses scripts to batch pack channel packages and ios script channel packages
Recently we have received a new demand, need to play a xx001-xx100 like a total of 100 such ipa channel package, no signature. (These ipa packages will be signed with enterprise certificates in the future and will not affect the AppStore.) All functions and contents of these packages are the same, the difference is that different packages provide a different string identifier when collecting statistics and connecting to our server. If we follow the conventional packaging method, we need to constantly modify the values in the project, and then package them one by one ...... How can this kind of untechnical activity be tolerated! After a simple thought, we can use shell scripts to package data in batches. Channel information can be stored in info. plist of the application. Batch Processing ideas: 1. by changing a setting or variable, the info. change a value in plist. 2. if you use the xcodebuild command for packaging and other processing segments, you can actually use the following methods: 1. the advantage of using multiple targets is that we can customize information in a more in-depth manner. The disadvantage is that operations are a little complicated and costly for us with this simple requirement. The script is similar to the following 2, but the variable is target. 2. use multiple buildSetting different build active architecture to set different User-Defined values. The first version of the script is provided by my colleagues. This method is used, it is a little simpler than the above method. The ideas and steps are as follows: 1. in Xcode build settings, multiple build active architectures are generated by copying release and named by channel names respectively. add the key named Channel under the User-Defined attribute and set different Channel values for different builds. 3. info. add the Channel key in plist and reference the setting $ {Channel} in User-Defined (the script is not pasted here due to the imperfect solution) when I saw this solution, it was not enough because it was still very troublesome to modify the engineering configuration and other related information. For us, the package we typed is actually only info. in plist, the predefined values are different. In fact, you don't need so many targets or so many buildsetting instances. You just need to use a script to Change info during packaging. the corresponding key value in plist. Find information and find that the command to modify the plist value already has a built-in tool PlistBuddy. However, this tool must be referenced using its absolute path before it can be referenced. The path is/usr/libexec/PlistBuddy, you can search for more functions of the tool. After adjustment, the script is: channels = (Channel 1 channel 2 channel 3) for I in $ {channels [@]} do xcodebuild-project./your project. Xcodeproj-scheme your scheme name-configuration Release archive-archivePath. /$ I/usr/libexec/PlistBuddy-c "Set: Channel" "$ I ". /$ I. xcarchive/Products/Applications /*. app/info. plist rm-Rf. /$ I. ipa xcodebuild-exportArchive-exportFormat ipa-archivePath. /archive. xcarchive-exportPath. /$ I. ipa-exportWithOriginalSigningIdentity rm-Rf. /$ I. xcarchive done [/code] is good. It is ready after completion. You can pack it in batches. There is no problem. Well, it seems very time-consuming ...... Looking back, let's analyze the packaging process: 1. use the xcodebuild command to generate the xcarchive file based on the project. 2. you can use the xcarchive file to export ipa. In this process, the signature is generated during a packaging process. xcarchive file. No signature or other operations have been performed for this file. In fact, we can directly modify the plist in the corresponding app file in this xcarchive package and then export it to ipa, in this way, you can share an xcarchive file, saving N times of packaging the file. Now Let's adjust it to get our final version: xcodebuild-project./your project. Xcodeproj-scheme your scheme name-configuration Release archive-archivePath. /archive channels = (Channel 1 channel 2 channel 3) for I in $ {channels [@]} do/usr/libexec/PlistBuddy-c "Set: channel "" $ I ". /archive. xcarchive/Products/Applications /*. app/info. plist rm-Rf. /$ I. ipa xcodebuild-exportArchive-exportFormat ipa-archivePath. /archive. xcarchive-exportPath. /$ I. ipa-exportWithOriginalSigningIdentity done rm-Rf ./Archive. xcarchive [/code] note that 1. Set a Channel key in advance in the info. plist file of the project, and write the default Channel value. 2. the corresponding certificate in the project must be configured; otherwise, the package may fail. 3. the ipa in this article are all unsigned. If you need a signature, you can search for it by yourself. It is easy to save this script as an archive file and drop it in the project directory. Use this method: Open the terminal, run the two-line command cd to your project directory [/code]. /archive [/code]. After the job is completed, you can use NSString * channel = [[[NSBundle mainBundle] infoDictionary] objectForKey: @ "Channel"] in the project. [/code] The channel information is obtained.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.