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 using the enterprise certificate in the future and will not affect the AppStore)
All the functions and content of these packages are the same. The difference is that different packages provide different string identifiers for statistics and connection 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. Change the value of info. plist in the project by changing a setting or variable.
2. Use the xcodebuild command for packaging and other processing

In fact, there are several ways to segment:
1. Use multiple targets
This advantage is more in-depth customization information, see Tang Qiao's article: http://blog.devtang.com/blog/2013/10/17/the-tech-detail-of-ape-client-1/
The disadvantage is that, for our simple needs, operations are slightly complicated and costly.
The script is similar to the following 2, but the variable is target.

2. Use multiple buildSetting
Set different User-Defined values for different build active Architectures
The first version of the script is provided by my colleagues. It is a little simpler than the above method.
The steps are as follows:
1. In Xcode build settings, multiple build active architectures are generated by copying release and named by channel names respectively.
2. Add the key named Channel under the User-Defined attribute and set different Channel values for different builds.
3. Add the Channel key to info. plist. The value references the setting $ {Channel} under User-Defined}
(Because the solution is not perfect, this script will not be posted here)

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. xcarchivedone

Okay. You can pack them in batches.

Packaging is okay. Well, it seems very time-consuming...

Let's go back and analyze the packaging process:
1. Use the xcodebuild command to generate the xcarchive file based on the project
2. Use the xcarchive file to export ipa, which can be signed during this process

During a packaging process, xx is generated. 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. /archivechannels = (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-exportWithOriginalSigningIdentitydonerm-Rf. /archive. xcarchive

Note that
1. Set a Channel key in advance in the info. plist file of the project, and write the default Channel value.
2. Configure the corresponding certificate in the project, or the package may fail.
3. the ipa mentioned in this article are all unsigned. If you need a signature, you can search for it by yourself, which is relatively simple.

Save the script as an archive file and drop it in the project directory. Usage:
Open the terminal and execute two lines of commands

Cd your project directory
./archive

Okay. After finishing the job, you can use it in the project.

NSString* channel = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Channel"];

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.