http://ccmos.tw/blog/2011/06/30/xcode4-port-program-to-idevice-without-idp/
2.修改Xcode的配置文件和二進制文件
下面的步驟稍微有點繁瑣,您應該瞭解UNIX命令行的基本操做,並瞭解一種命令行文本編輯器,本文使用的是vim。儘管這裏會給出完整的代碼,可是關於修改和保存代碼的基本操做,再也不贅述。下面的操做請先
將Xcode按Command+Q徹底關閉。
(1)修改配置文件
進入目錄並備份原文件
(4.一、4.二、4.3在這裏主要的差異是SDK的目錄名不一樣)
(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/iPhoneOS5.0.sdk
(Xcode4.3.2請執行)
cd
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
(Xcode4.5請執行)
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk
sudo cp SDKSettings.plist SDKSettings.plist.orig
進行編輯
(Xcode 4.5以前)
sudo vim SDKSettings.plist
將如下兩段中的YES改成NO
<key>CODE_SIGNING_REQUIRED</key>
<string>
YES
</string>
和
<key>ENTITLEMENTS_REQUIRED</key>
<string>
YES
</string>
Xcode 4.5的plist格式再也不爲XML,而是改成了Apple本身的二進制格式,咱們使用Xcode自己來編輯這個plist文件,命令是
sudo /Applications/Xcode.app/Contents/MacOS/Xcode ./SDKSettings.plist
會啓動Xcode的圖形界面,咱們展開DefaultProperties分支,將下面的CODE_SIGNING_REQUIRED和ENTITLEMENTS_REQUIRED兩個屬性改成NO
下面修改另一個文件
進入目錄並備份原文件
(Xcode4.1/4.2請執行)
cd /Developer/Platforms/iPhoneOS.platform/
(Xcode4.3/4.4/4.5請執行)
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform
備份
sudo cp Info.plist Info.plist.orig
進行編輯
sudo vim Info.plist
將所有的
XCiPhoneOSCodeSignContext
修改爲
XCCodeSignContext,網上的大部分文章說有2處,但我找到了3處,多是Xcode 4.1要多一處?
(Xcode 4.2/4.3/4.3.2也有三處)總之都改掉了。提示:在在vim中輸入
/要搜索的內容來搜索,按
n鍵是搜索下一處。
(Xcode 4.5)編輯命令以下
sudo /Applications/Xcode.app/Contents/MacOS/Xcode /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Info.plist
Xcode 4.5也有三處,分別在DefaultProperties分支下、RuntimeRequirements分支下和OverrideProperties分支下。
(2)二進制補丁
#在桌面上創建script這個腳本
#
(Xcode 4.1執行)在編輯器中輸入以下內容
#!/bin/bash
cd /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS\ Build\ System\ Support.xcplugin/Contents/MacOS/
dd if=iPhoneOS\ Build\ System\ Support of=working bs=500 count=255
printf "xc3x26x00x00" >> working
/bin/mv -n iPhoneOS\ Build\ System\ Support iPhoneOS\ Build\ System\ Support.original
/bin/mv working iPhoneOS\ Build\ System\ Support
chmod a+x iPhoneOS\ Build\ System\ Support
#
(Xcode 4.2執行)在編輯器中輸入以下內容
#!/bin/bash
cd /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS\ Build\ System\ Support.xcplugin/Contents/MacOS/
dd if=iPhoneOS\ Build\ System\ Support of=working bs=500 count=255
printf "xc3x26x00x00" >> working
/bin/mv -n iPhoneOS\ Build\ System\ Support iPhoneOS\ Build\ System\ Support.original
/bin/mv working iPhoneOS\ Build\ System\ Support
chmod a+x iPhoneOS\ Build\ System\ Support
保存並退出。(4.1和4.2在這裏的區別也是目錄名不一樣,就是代碼中綠色的部分。4.1是
Plug-ins而4.2是
PrivatePlugIns
)
授予這個腳本執行權限並執行它
chmod 777 script
./script
正常的話應該輸出(具體的數字可能有差異)
231+1 records in
231+1 records out
115904 bytes transferred in 0.001738 secs (66694555 bytes/sec)
#
(Xcode 4.3注意)在Xcode 4.3版本中,我沒有找到
iPhoneOS Build System Support.xcplugin
這個插件,所以我跳過了這個步驟,而且最終也成功的進行了聯機調試。所以我我的認爲Xcode 4.3沒有必要執行「二進制補丁」這一步驟。請各位朋友測試~!
#
(Xcode 4.3.2/4.4/4.5注意)在Xcode 4.3.2版本中,咱們能夠找到
iPhoneOS Build System Support.xcplugin,但我沒有修改它,仍然能夠進行聯機調試。這個修改步驟是從Xcode 3.X中繼承過來的,咱們有理由猜想,在Xcode 4.x版本中,已經不須要修改這個文件了。(2012年5月28日更新)
至此,對SDK中配置文件和二進制文件的修改就完成了
3.準備自定義的生成後腳本
鏈接互聯網後執行
#(Xcode 4.1/4.2執行)
mkdir /Developer/iphoneentitlements401
cd /Developer/iphoneentitlements401
curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt
mv gen_entitlements.txt gen_entitlements.py
chmod 777 gen_entitlements.py
#(Xcode 4.3/4.4/4.5執行)
mkdir /Applications/Xcode.app/Contents/Developer/iphoneentitlements
cd
/Applications/Xcode.app/Contents/Developer/iphoneentitlements
curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt
mv gen_entitlements.txt gen_entitlements.py
chmod 777 gen_entitlements.py
熱心網友Ringo_D指出,這裏可能涉及到權限問題。我作的時候貌似沒有出啥問題,若是您在執行這段代碼時遇到Permission denied提示的話,請將相應的語句前面加上sudo以獲取超級權限。(2012年6月15日更新)
若是您已經聯網,則請直接轉到步驟4,若是您沒有聯網,那麼請在相應目錄手動建立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.修改工程設置
特別注意:本階段以前的修改配置文件、準備腳本等,只須要作一次。但本階段的操做,對每一個須要真機調試的工程都要作一遍。
這個步驟的主要做用是支持真機調試,若是不作這個步驟,仍然能夠經過步驟5來生成ipa在真機上運行,可是沒法使用Xcode內置的調試器對在真機上運行的程序進行單步跟蹤。若是您的程序在點擊Run真機調試時秒退,請檢查此步驟是否正確完成。
(1)禁用Xcode自動的簽名操做
至此配置所有完成,下面就能夠插上iPhone,從新選擇生成目標來測試一下在線調試了!若是是第一次使用該設備調試,請先在Organizer中將設備切換爲開發模式,具體操做請見常見問題5。