unity基础开发----ipad的配置信息

Xcode 4.1/4.2/4.3 免证书(iDP)开发+真机调试+生成IPA全攻略,昨天做个ipad的虚拟现实项目,需要在ipad上演示就在网上找了一下相关的信息总结一下备用。详细的xcode的配置信息看附件文档。

 

Xcode 4.1/4.2/4.3 免证书(iDP)开发+真机调试+生成IPA全攻略(99美金省了)  

开发环境使用的是目前为止最新的稳定版软件:Mac OS X Lion 10.7 + Xcode 4.1 

目前Xcode 4.2 Preview版也已经发布,据说其修改方法跟4.1非常类似,只改动了一行代码,请参看参考文章的第二篇。本文仍以4.1版本为例。

更新:现在Xcode 4.2正式版和iOS 5均已发布,下面补充上4.2的修改方法。(2011-10-24

各步骤会标明版本,比如(Xcode4.1请执行)和(Xcode4.2请执行),4.2.1的修改方法与4.2完全相同

未标明的步骤为两个版本均需执行的步骤!

更新:现在Xcode 4.3已发布,修改方法类似,Xcode 4.3的修改步骤将以(Xcode4.3请执行)标出(2012-2-7

201227日更新:

目前本人已经测试并证实有效的平台有

Xcode 4.1

iPod touch 4 iOS 4.3.3

Xcode 4.2

iPod touch 4 iOS 4.3.3

iPod touch 4 iOS 5.0

iPod touch 4 iOS 5.0.1

Xcode 4.2.1

iPod touch 4 iOS 4.3.3

iPod touch 4 iOS 5.0.1

iPhone 4S iOS 5.0.1(5A406)

Xcode 4.3(201227日更新)

iPhone 4S iOS 5.0.1(5A406)

另外,操作系统的版本貌似对调试影响不大,这期间用过的系统有Mac OS X 10.7~10.7.3,都没有问题。

当然您需要先越狱您的设备并通过Cydia安装AppSync 

本文参考了多篇文章,综合其中的方法,并修正其中的错误,整理而成。

未经许可,请勿转载。本文首次发表于http://kqwd.blog.163.com/

参考的文章有:

http://laolang.cn/back-end-develop/helloworld-iphone-developer.html

http://ccmos.tw/blog/2011/06/30/xcode4-port-program-to-idevice-without-idp/

http://www.cnblogs.com/flyingzl/articles/2207717.html


众所周知,在Xcode上开发的程序只能在模拟器中运行,如果要放到真机上则要花费99美金购买开发者证书iDP。这严重阻碍了我等草根开发者探索的脚步。写个小程序,同学间分享一下这个小小的愿望都不能满足,自然不能善罢甘休。

在没有iDP的情况下,要想将程序放到iPhone上调试,并最终发布IPA用于分享,需要以下几个步骤:

1.自己为自己颁发一个证书用于为生成的程序签名

2.修改工程配置以及Xcode的配置文件和二进制文件以阻止其验证和签名

3.通过自定义生成步骤,用伪造的证书为应用程序签名

4.使用一点小trick来生成IPA文件

开始之前的友情提示:

1. 本文给有一定基础的朋友看,各种命令是免不了的。UNIX中的基本命令比如cpmvcdchmodsudo啥的还有vim编辑器,如果您都没听说过,强烈建议您不要尝试本文提到的修改。一旦改错了轻则Xcode挂掉,重则系统崩溃。

2. 本文的每一个步骤都是必须的,如果您哪一步没有得到预期的结果,请不要继续,以免发生更加意外的事情。。。

3. 如果遇到解决不了的问题欢迎留言询问,务必给出详细的错误信息,否则无法判断。博主恕不解答类似于如何执行脚本代码,如何赋予执行权限,如何使用vim编辑器(如何保存)等与iOS开发无关的UNIX基础问题。

1.创建证书

创建证书的过程比较简单,打开实用工具-钥匙串访问。然后在菜单栏里点击钥匙串访问-证书助理-创建证书来打开向导。第一个步骤比较重要,必须要把名称命名为iPhone Developer,将类型设定为代码签名,将"让我覆盖这些默认值"选中。之后的步骤无需更改,一路点击确定继续来完成这个向导就可以。

2.修改Xcode的配置文件和二进制文件

下面的步骤稍微有点繁琐,您应该了解UNIX命令行的基本操作,并了解一种命令行文本编辑器,本文使用的是vim。尽管这里会给出完整的代码,但是关于修改和保存代码的基本操作,不再赘述。下面的操作请先XcodeCommand+Q完全关闭

(1)修改配置文件

进入目录并备份原文件4.14.24.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

sudo cp SDKSettings.plist SDKSettings.plist.orig

进行编辑

sudo vim SDKSettings.plist

将以下两段中的YES改为NO

<key>CODE_SIGNING_REQUIRED</key>

<string>YES</string>

<key>ENTITLEMENTS_REQUIRED</key>

<string>YES</string>

下面修改另外一个文件

进入目录并备份原文件

Xcode4.1/4.2请执行)cd /Developer/Platforms/iPhoneOS.platform/

Xcode4.3请执行)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也有三处)总之都改掉了。提示:在在vim中输入/要搜索的内容来搜索,按n键是搜索下一处。

(2)二进制补丁

#在桌面上建立script这个脚本

cd ~/Desktop

vim 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.14.2在这里的区别也是目录名不同,就是代码中绿色的部分。4.1Plug-ins4.2PrivatePlugIns

授予这个脚本执行权限并执行它

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没有必要执行二进制补丁这一步骤。请各位朋友测试~

至此,对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执行)

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

如果您已经联网,则请直接转到步骤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自动的签名操作 

将工程配置中所有的Code Signing选项全部设为Don't Code Sign,如图。可能需要先点击“All”让这个选项显示出来

(2)添加自定义的生成后脚本

Build Phases中添加一个Phase,右下角的Add Build Phase,然后单击Add Run Script,输入以下脚本

(对于Xcode 4.1/4.2

export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate

if [ "${PLATFORM_NAME}" == "iphoneos" ] || [ "${PLATFORM_NAME}" == "ipados" ]; 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

(对于Xcode 4.3

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,重新选择生成目标来测试一下在线调试了!如果是第一次使用该设备调试,请先在Organizer中将设备切换为开发模式,具体操作请见常见问题5

5.旁门左道生成IPA文件

如果我的程序调试好了,怎么才能发给别人用呢?正常情况下IPA文件是从XcodeOrganizer中输出的,但是我们没有证书,这样输出会产生错误。我们只能用个小trick来完成这个操作了。

先将代码生成为Release目标,然后打开工程的输出文件夹,通常情况下这个目录是

/Users/你都用户名/Library/Developer/Xcode/DerivedData/以工程名打头的文件夹/Build/Products/Release-iphoneos

很纠结吧~这个目录下有个.app的文件,就是生成的程序了。把这个.app拖到iTunes中,它会出现在应用程序那个列表中,然后再把它从iTunes的那个列表中拖出来(比如拖到桌面),发生了什么?哈哈,它就这样变成.ipa了!

把这个.ipa发给朋友,大家就可以跟您一起分享这个程序了。

 

Dr. Allan Fowler is a professor of game design at Kennesaw State University who lives in Atlanta, Georgia. He is a published author, game designer, and dedicated educator. When not looking after his two children, in his spare time he makes games, practices martial arts, and is a keen amateur photographer. Dr. Fowler holds second-degree black belts in both Shotokan karate and Goju-ryu karate and has competed in state and international tournaments. Philip Chu is a general-purpose programmer, accidental game developer, and aspiring writer (he wishes he wrote Snow Crash). Since his first encounter with an Apple II in high school, Phil has over two decades of professional software development experience in the semiconductor, defense/government, computer graphics, Internet, mobile and video game industries. He received a Bachelor's degree in Computer Science and Engineering from MIT (Course 6-3, for those in the know) and a Master’s degree in Computer Science from Johns Hopkins University. Phil is currently living the self-employed indie life in sunny Huntington Beach, California, where he performs contract work under his own consulting firm, Technicat, LLC. Projects have included 3D content creation tools (Nendo), video games (Darkwatch, Tech Deck: Bare Knuckle Grind), virtual worlds (Blue Mars, Playstation@Home), and some occasional Java work. But he still misses working on Lisp machines. For his own projects, Phil develops and self-publishes Mac/PC, web and mobile games with the Unity engine, under the Fugu Games and HyperBowl brands (the latter is licensed from Hyper Entertainment). Check them out at http://fugugames.com/ and http://hyperbowl3d.com/. Phil blogs and tweets regularly (http://fugutalk.com/ and @fugugames), and maintains game development reference material and software development essays on http://technicat.com/, some of which have been included as reading material in college courses and published in venues such as the MIT Entrepreneurial Review and the Nintendo Developer Support Group site, as well as the Nook and Kindle.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值