1.创建证书
实用工具-钥匙串访问。然后在菜单栏里点击钥匙串访问-证书助理-创建证书来打开向导。
证书名称必须为iPhone Developer,将类型设定为代码签名,勾选”让我覆盖这些默认值”,之后就一路Next。
2.环境配置
首先确认已退出Xcode,然后开始修改配置文件:
打开“终端”(1-4步都是在终端中执行)
(1)修改 SDKSettings.plist
先备份原文件:cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/
sudo cp SDKSettings.plist SDKSettings.plist.orig
进行编辑:sudo vi SDKSettings.plist
将以下两段中的YES改为NO<key>CODE_SIGNING_REQUIRED</key>
<string>YES</string>
...
<key>ENTITLEMENTS_REQUIRED</key>
<string>YES</string>
(2)修改 Info.plist 文件
同样先备份原文件:cd /Developer/Platforms/iPhoneOS.platform/
sudo cp Info.plist Info.plist.orig
进行编辑:sudo vi Info.plist
将全部的XCiPhoneOSCodeSignContext 修改成 XCCodeSignContext,一共有 3 处。
(3)在桌面上新建并编辑名为script的脚本:cd ~/Desktop
vi script
输入以下内容:(点击“i”进入编辑模式)#!/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
保存并退出(点击Esc,输入:wq)。
授予这个脚本执行权限并执行它chmod 777 script
./script
运行成功会输出类似结果:
223+1 records in
223+1 records out
111648 bytes transferred in 0.002678 secs (41692099 bytes/sec)
(4)生成脚本
执行命令: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
如果上面的代码运行有问题,也可以在/Developer目录下新建一个entitlements.py文件,并把下面的代码复制到该文件中,最后赋予777权限:
#!/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()
(5)Xcode中的设置,以下步骤需要在每个工程中都设置一次。
1.工程设置,步骤如图:
2.脚本设置,将下面的代码添加到Phase中:export
CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ]; then
/Developer/iphoneentitlements401/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
至此配置全部完成,接下来就可以连接iOS设备进行程序调试了.