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。