The development environment uses the latest stable version of software so far: Mac OS X Lion 10.7 + Xcode 4.1
The versions are marked in each step, for example, Xcode4.1 and Xcode4.2)
Steps not marked are required for both versions!
Of course, you need to first jailbreak your device and install AppSync through Cydia
As we all know, programs developed on Xcode can only run in simulators. If you want to put them on a real machine, you will spend $99 to buy the developer certificate iDP. This severely hinders the development of grassroots developers. When I write a small program, I can't satisfy all my wishes. Naturally, I cannot give up.
In the absence of iDP, the following steps are required to put the program on the iPhone for debugging and finally release IPA for sharing:
1. issue a certificate for yourself to sign the generated program
2. Modify the project configuration and Xcode configuration files and binary files to prevent them from being verified and signed.
3. Use the custom generation step to sign the application with a forged certificate
4. Use a little trick to generate the IPA File
Tips before the start:
1.This article shows to some friends who have some basic knowledge that various commands are inevitable. Basic commands in UNIX, such as cp, mv, cd, chmod, sudo, And the vim editor. If you have never heard of them, we strongly recommend that you do not try the modifications mentioned in this article. If the error is corrected, Xcode crashes and the system crashes.
2.Every step in this article is required. If you do not get the expected results, do not continue to avoid unexpected events...
3.If you encounter a problem that cannot be solved, please leave a message to ask. Make sure to provide detailed error information; otherwise, you will not be able to judge.
1. Create a certificate
The process of creating a certificate is relatively simple. Open the utility-key string access. In the menu bar, click Key string access-certificate assistant-create certificate to open the wizard. The first step is important. You must name it iPhone Developer, set the type to code signature, and select "let me override these default values. The subsequent steps do not need to be changed. Click "OK" and "continue" to complete the wizard.
2. modify the configuration file and binary file of Xcode.
The following steps are a little tedious. you should understand the basic operations of UNIX command lines and a command line text editor. This article uses vim. Although the complete code is provided here, the basic operations on modifying and saving the Code are not described in detail. Follow these steps:Close Xcode by Command + Q.
(1) modify the configuration file
Go to the directory and back up the original file(The main difference between 4.1 and 4.2 is that the SDK directory name is different)
(Execute Xcode4.1)
cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/
(Execute Xcode4.2)
cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/
Save the file and use vim to edit it:
sudo cp SDKSettings.plist SDKSettings.plist.orig
sudo vim SDKSettings.plist
Change "YES" in the following two paragraphs to "NO:
<Key> CODE_SIGNING_REQUIRED </key>
<String> YES </string>
And
<Key> ENTITLEMENTS_REQUIRED </key>
<String> YES </string>
Next, modify another file, enter the directory, back up the original file, and edit it:
cd /Developer/Platforms/iPhoneOS.platform/
sudo cp Info.plist Info.plist.orig
sudo vi Info.plist
Set allXCiPhoneOSCodeSignContextModifyXCCodeSignContextThere are two articles on the Internet, but I found three. Maybe Xcode 4.1 requires one more?(There are also three parts in Xcode 4.2)All of them have been replaced. Tip: Enter/search content in vim to search. Press the n key to search for the next place.
(2) binary patch
Create a script on the desktop:
cd ~/Desktop
vim script
(Executed in Xcode 4.1)Enter the following content in the Editor:
#! /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. original
/Bin/mv working iPhoneOS \ Build \ System \ Support
Chmod a + x iPhoneOS \ Build \ System \ Support
(Executed in Xcode 4.2)Enter the following content in the Editor:
#!/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
Save and exit. (The difference between 4.1 and 4.2 is that the directory name is different, that is, the green part of the code. 4.1 isPlug-insAnd 4.2 isPrivatePlugIns)
Grant this script execution permission and execute it
chmod 777 script
./script
Normally output (the specific numbers may be different)
231+1 records in
231+1 records out
115904 bytes transferred in 0.001738 secs (66694555 bytes/sec)
Now, the configuration files and binary files in the SDK are modified.
3. Prepare a custom post-generated script
Run
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
If you are already online, go directly to Step 4. If you are not online, manually create/Developer/iphoneentitlements401/gen_entitlements.py and grant it the execution permission. The content of this file is
#!/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. Modify Project Settings
Note: you only need to modify the configuration file and prepare the script once before this phase. However, this phase of operation is required for every project that requires real machine debugging.
The main function of this step is to support debugging on the real machine. If this step is not performed, you can still generate the ipa to run on the real machine through Step 5, however, you cannot use the Xcode built-in debugger to track programs running on a real machine in one step. If your program is switched back in seconds when you click Run real machine debugging, check whether this step is completed correctly.
(1) Disable Xcode's Automatic Signature operation
Set all the Code Signing options in the project configuration to Don't Code Sign ,. You may need to click "All" to display this option.
(2) Add custom generated scripts
Add a Phase in Build Phases, Add Build Phase in the lower right corner, and click Add Run Script,
Enter the following script
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
Now that all the configurations are complete, you can plug in the iPhone and select the test device to debug the real machine.
Reference articles:
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