XCode4.3.3/4.2/4.3 + iOS5.1 無證書開發 、真機調試、生成IPA
環境:
Mac OS X 10.7.4+XCode4.3.3+ iPad3
特别說明:
Xcode4.3.2 , Xcode4.3.3 都是免安裝的,打開dmg後,隻有一個Xcode.app檔案。安裝方法是直接将Xcode.app拖放到“應用程式”(Applications)的目錄即可使用。安裝後沒有Developer目錄,是以以下的制作方法也是Xcode.app的安裝包中進行的。
而xcode4.1/xcode4.2,則是安裝到/Developer/目錄下,從該目錄下去找相應的檔案。
另外,你的iPhone或iPad必須越獄的。
1、生成iPhone Developer證書
在“使用工具”中使用 “鑰匙串通路” 工具,“鑰匙串通路->證書助理->建立證書”名稱必須寫成 “iPhone Developer”其他全部預設,直至證書生成完成。
2、修改XCode系統檔案
(2.1) 運作指令:
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
sudo vim SDKSettings.plist
此時進入vim檔案編輯狀态(會提示password 輸入Mac登陸密碼後回車)
(注:i 進入Insert狀态,修改完成後按ESC鍵退回到指令狀态,Q退出 :w 儲存 :q 退出)
将下面兩個字段修改為NO
<key>CODE_SIGNING_REQUIRED</key>
<string>YES</string>
<key>ENTITLEMENTS_REQUIRED</key>
<string>YES</string>
其它版本該檔案所在的位置:
(Xcode4.1) cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/
(Xcode4.2)cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/
(Xcode4.3)cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
(Xcode4.3.2)cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
(2.2) 進入另外一個目錄
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
進行編輯:
sudo vim Info.plist
将全部的XCiPhoneOSCodeSignContext 修改成 XCCodeSignContext。儲存退出即可。
(提示:在vim中輸入/要搜尋的内容來搜尋,按n鍵是搜尋下一處。)
其它版本該檔案所在的目錄:
(Xcode4.1/4.2)cd /Developer/Platforms/iPhoneOS.platform/
(Xcode4.3/4.3.2)cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
3、增加檔案gen_entitlements.py
cd /Applications/Xcode.app/Contents/Developer/
mkdir iphoneentitlements(如果建立失敗可直接通過Finder 前往 /Applications/Xcode.app/Contents/Developer/手動去建立此檔案夾)
cd iphoneentitlements
curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt(通過網站下載下傳了一個檔案)
mv gen_entitlements.txt gen_entitlements.py
如果沒有連接配接網絡的,那麼請在相應目錄手動建立gen_entitlements.py并授予其執行權限,這個檔案的内容為:
#!/usr/bin/env python
import sys
import struct
if len(sys.argv) != 3:
print "Usage: %s appname dest_file.xcent" % sys.argv[0]
sys.exit(-1)
APPNAME = sys.argv[1]
DEST = sys.argv[2]
if not DEST.endswith('.xml') and not DEST.endswith('.xcent'):
print "Dest must be .xml (for ldid) or .xcent (for codesign)"
sys.exit(-1)
entitlements = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>application-identifier</key>
<string>%s</string>
<key>get-task-allow</key>
<true/>
</dict>
</plist>
""" % APPNAME
f = open(DEST,'w')
if DEST.endswith('.xcent'):
f.write("\xfa\xde\x71\x71")
f.write(struct.pack('>L', len(entitlements) + 8))
f.write(entitlements)
f.close()
4、配置XCode項目
特别注意:本階段之前的修改配置檔案、準備腳本等,隻需要做一次。
但本階段的操作,對每個需要真機調試的工程都要做一遍。
(1)禁用Xcode自動的簽名操作
将工程配置中所有的Code Signing選項全部設為Don't Code Sign,如圖。可能需要先點選“All”讓這個選項顯示出來。如下:
(2)添加自定義的生成後腳本
(對于Xcode 4.3/4.3.2)
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ] || [ "${PLATFORM_NAME}" == "ipados" ]; then
/Applications/Xcode.app/Contents/Developer/iphoneentitlements/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent";
codesign -f -s "iPhone Developer" --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"
fi
如下:
至此配置全部完成,下面就可以插上iPhone或iPad,重新選擇生成目标來測試一下線上調試了!如果是第一次使用該裝置調試,請先在Organizer中将裝置切換為開發模式。
從Xcode工具欄右上角打開Organizer,如下圖:
5、生成IPA檔案
正常情況下IPA檔案是從Xcode的Organizer中輸出的,但是我們沒有證書,這樣輸出會産生錯誤。我們隻能用個小trick來完成這個操作了。
先将代碼生成為Release目标,然後打開工程的輸出檔案夾,通常情況下這個目錄是
/Users/你的使用者名/Library/Developer/Xcode/DerivedData/以工程名打頭的檔案夾/Build/Products/Release-iphoneos
很糾結吧~這個目錄下有個.app的檔案,就是生成的程式了。把這個.app拖到iTunes中,它會出現在應用程式那個清單中,然後再把它從iTunes的那個清單中拖出來(比如拖到桌面),發生了什麼?哈哈,它就這樣變成.ipa了!