Recently we have received a new demand, need to play similar xx001-xx100 a total of 100 such IPA channel package, do not need to sign. (This batch of IPA package will be signed with Enterprise certificate, will not affect AppStore)
All the functions and contents of these packages are the same, except that different packages provide a different string indication when they are counted and connected to our server.
If you follow the usual packaging, we need to constantly modify the values in the project, and then package ... How can you endure this kind of work without technical content?
After a simple thought, we can use shell scripts to implement bulk packaging, and channel information can be stored in the application's info.plist.
Batch processing ideas:
1. Changing a setting or variable to cause a change in the value of a info.plist in the project
2. Use the Xcodebuild command for packaging and other processing
In fact, there are several ways to subdivide the words:
1. Use multiple target
The advantage of this is that you can customize the information in depth, see Tang Qi's article: http://blog.devtang.com/blog/2013/10/17/the-tech-detail-of-ape-client-1/
The disadvantage is that for our simple requirements, the operation is slightly cumbersome and expensive.
The script is similar to the following 2, except that the variable is target.
2. Use multiple buildsetting
Different build active architecture set different user-defined values
The first version of the script is provided by my colleague, which is a slightly simpler approach than the one above.
The ideas and steps are as follows:
1. In the build settings of Xcode, generate multiple build active architecture by copy release, named by Channel name, respectively
2. Add a key named Channel under the User-defined property to set different channel values for different builds
3. Add Channel key in Info.plist, value reference setting under User-defined ${channel}
(The script is not posted here because the scenario is not perfect)
When I see this kind of solution is still not satisfied, because the need to change the project configuration and other related information, is still very troublesome.
For us, the package is actually only info.plist in a preset value is not the same, in fact, you can not need so many target or so many buildsetting, just in the packaging, with a script to change the corresponding key value in Info.plist.
Find data Find, command modify Plist value already has built-in tool Plistbuddy, but this tool uses its absolute path to refer to, the path is/usr/libexec/plistbuddy, the tool's more function is interested can search by oneself.
After the adjustment, the script is:
Channels= (channel1Channel2Channel3) forIinch ${channels[@]} DoXcodebuild-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
All right, we got it, we can pack it in bulk.
Packing no problem, um, but it seems to be time-consuming ah ...
Back to our analysis of the packaging process:
1. Use the Xcodebuild command to generate a xcarchive file from the project
2. Export the IPA using the xcarchive file, which can be signed in the process
For a single packaging process, During the generation of the Xx.xcarchive file, this file has not yet performed any signature and other operations, in fact, we can directly modify the Xcarchive package in the corresponding app files within the plist, and then exported to IPA, so that you can share a xcarchive file, save n multiple packaging out The time of the file.
Okay, let's adjust. 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-export Format IPA- Archivepath./archive.xcarchive-exportpath./ $i . IPA- Exportwithoriginalsigningidentitydone rm-rf./archive.xcarchive
It is important to note that
1. In the project's Info.plist file, set a channel key in advance, and the value is written on the default channel.
2. The corresponding certificate in the project, etc. or to be configured, or the package may fail
3. The IPA in this article is unsigned and needs to be signed to search by itself, relatively simple
Save the script as a archive file, and leave it in the project directory, using the following method:
Open terminal, execute two lines of command
cd 你的工程目录
./archive
Okay, finish the call, so you're in the project, using
NSString* channel = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Channel"];
Get the channel information.
iOS uses scripts to bulk channel packages