1. 程式人生 > >iOS 多渠道打包的解決方案

iOS 多渠道打包的解決方案

環境:xcode 6.3.2
開始的思路是用指令碼 解壓.ipa檔案 ,修改.app裡面的自定義渠道檔案,然後再壓縮成ipa檔案。
後來發現打出來的手機裝不上。
於是主意打在了.xcarchive 檔案上。

指令碼如下

#!/bin/sh
#在工程的info.plist 相同路徑下 建立Channel.dat檔案作為 渠道號讀取的檔案
#建立這個指令碼檔案archive.sh(記得加可執行許可權)和渠道檔案Channels.dat
#用xcode打包後
#請將xcode archive 後的 XXXX.xcarchive檔案 與 archive.sh 和 Channels.dat 檔案放在相同路徑下
shpath="/Users/Admin/Tiger/iOS/渠道打包" #指令碼路徑 xcarchivename="XXX.xcarchive" #xcarchive 檔名 xcarchivesub="Products/Applications" appname="XXX.app" #程式target名稱 distDir="./Archives" #打包後文件儲存目錄 profile="LSZAdhocDistribution" #profile 檔案 version="1.5" rm -rdf "$distDir" mkdir "$distDir
"
for line in $(cat channels.dat) #讀取渠道號檔案並進行迴圈 do ipafilename=`echo $line|cut -f1 -d':'` sourceid=`echo $line|cut -f2 -d':'` #echo "ipafilename=$ipaname" #echo "sourceid=$sourceid" targetName="Tripsters" #echo "sourceid=$sourceid" #echo "ipafilename=$ipafilename" cd $shpath cd $xcarchivename cd $xcarchivesub
cd $appname #echo "replace Channel.dat before: " #cat Channel.dat echo "$sourceid" > Channel.dat #echo "replace Channel.dat after: " #cat Channel.dat cd $shpath archivePath=$shpath/$xcarchivename ipaPath="$distDir/${targetName}_${version}_${sourceid}.ipa" echo "Creating ipa..." xcodebuild -exportArchive -archivePath $archivePath -exportPath $ipaPath -exportFormat ipa -exportProvisioningProfile "$profile" done

Channels.dat 檔案內容

91助手:91_Store
同步推:TongBuTui_Store
PP助手:PP_Store
蘋果園:PingGuoYuan_Store
威鋒源:WeiFeng_Store
搜狐應用市場:Sohu_Store

Channel.dat 檔案內容

91_Store

Channel.dat 檔案讀取

 var channelid = "App Store"
 var filePath = NSBundle.mainBundle().pathForResource("Channel", ofType: "dat")
 if String.isNotEmptyString(filePath) {
     var channelString = String(contentsOfFile: filePath!, encoding: NSUTF8StringEncoding, error: nil)
     if String.isNotEmptyString(channelString) {
         channelid = channelString!
     }
  }