Vital Stats:
iOS 4.0.1
Xcode 3.2.3
Mac OSX 10.6.4 Snow Leopard
iPhones 3G, 3GS, 4 (I finally have the whole lineup!)
PROBLEM: I still can’t get iPhone 4 working. If you have one, please try it and help me out! UPDATE: Found the cause of the problem to be certain status bar libraries installed alongside other apps. I’m not sure why they cause the problem, but see full notes at the bottom of the post.
The Goal: As usual, we want to be able to click “build and go” in Xcode and get the app we’re working on to load to the phone and start up. Also, we want to be able to debug from within Xcode itself. After all, Xcode is cool, and terminal+makefiles+gcc+gdb is lame.
Abstract: The plan remains unchanged from the 3.x method. In fact, you commenters practically wrote this one for me. This time we’re going to tell Xcode that it doesn’t need to codesign for iPhoneOS targets, then we’re going to tell it don’tcodesign for iPhoneOS targets, then we’re going to tell it, well, actually, codesign but do it using our script, not your built in method.
The Process: With Xcode closed and your device unplugged from the computer,
- If you’ve done this step before for previous guides, you may ignore it. You’ll need a code signing identity in order to sign code to run on the device. Normally, this would be issued by Apple, but later on we’ll break the signature check so you can make a “Self-Signing Identity” using this guide from apple (coral). Note that you should name the identity “iPhone Developer” EXACTLY to avoid having to change a bunch of the steps below.
- On your jailbroken iPhone, install the app AppSync. Add the source http://cydia.hackulo.us to cydia. You’ll get a warning about pirating software: this patch, by virtue of breaking Apple’s DRM so that we can install our own app, also enables us to install cracked App Store apps. Don’t do that. It’s immoral, fails to support legitimate developers who should be rewarded for their effort, and perhaps above all, pirating $2 cell phone apps is just ultra lame. But since our purposes are not nefarious, dismiss the warning. From this repo, install the package AppSync for OS 4.0, and for good measure, reboot the device.
- Make some Plist adjustments, starting with SDKSettings.plist:
cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk sudo cp SDKSettings.plist SDKSettings.plist.orig sudo vi SDKSettings.plist
Find
CODE_SIGNING_REQUIRED YES
and change YES to NO
then findENTITLEMENTS_REQUIRED YES
and change YES to NO again. HINT: in vi, you can type the ‘/’ key in order to “Cmd-F”
- Now, move on to the platform Info.plist
cd /Developer/Platforms/iPhoneOS.platform/ sudo cp Info.plist Info.plist.orig sudo vi Info.plist
Two times, the following appears:
CODE_SIGN_CONTEXT_CLASS XCiPhoneOSCodeSignContext
Find each occurrence and replace the block
XCiPhoneOSCodeSignContext
with
XCCodeSignContext
- And now the real bad boy, some binary patching of Xcode:
cd ~/Desktop vi script
hit the “i” key and copy/paste:
#!/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 "\xc3\x26\x00\x00" >> 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
type the keys, in order: “:” “x” “enter”
chmod 777 script ./script
If it works right, you should see something like
$ ./script 223+1 records in 223+1 records out 111648 bytes transferred in 0.002678 secs (41692099 bytes/sec)
At this point, you’re done telling Xcode it doesn’t need to codesign. Now, we tell it don’t codesign:
- With a new project open and ready to go (presumably you want to debug this one, though once you change these settings once, they’ll persist from project to project) open Project>Edit Project Settings (from the menu). Click on the “Build” tab.
Find “Code Signing Identity” and its child “Any iPhoneOS Device” in the list, and set both to the entry “don’t code sign”Now you’ve told Xcode “don’t codesign.”
- Almost done: time to tell Xcode “well, actually you should codesign.”
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
-
And finally, to link the device and computer. Plug your iPhone in and open Xcode. Open Window>Organizer. Select the device from the list on the left hand side, and click “Use for development.” You’ll be prompted for a provisioning website login, click cancel. It’s there to make legitimate provisioning easier, but doesn’t make illegitimate not-provisioning more difficult.
Now you’re good to go! But there’s just one last thing. You have to do this last part for every new project you make. Go to the menu Project > New Build Phase > New Run Script Build Phase. In the window, copy/paste this:
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
That will call the script you just downloaded in step 5 to sign our app with a fake signature. This is important only for debugging. If you do build and go otherwise, the app will load to the phone, but the app will fail to launch and you’ll get:
Error from debugger: The program being debugged is not being run
That should do it. Take all those steps and you should be home free for JBDev without paying $99.
CREDITS: Once again, credit for this process goes to various posters in this forum thread at iphonedevsdk.com. All of these steps are there somewhere, it just took a while to re piece them together in the right combination.
iPhone 4 Issue (UPDATE see below): So the method above has been tested working for my 3G and my 3GS. I don’t have my 2G right with me, but I expect it’s no different from the previous method, given that it can’t run iOS4.
The problem that I run into is this:
[Session started at 2010-08-04 20:35:02 -0400.]
//GDB stuff
Program loaded.
target remote-mobile /tmp/.XcodeGDBRemote-93925-69
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
run
Running…
[Switching to thread 11523]
[Switching to thread 11523]
continue
warning: Unable to read symbols for "/Library/MobileSubstrate/MobileSubstrate.dylib" (file not found).
// A bunch of other lib load warnings like this here...
warning: Unable to read symbols for "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0.1/Symbols/usr/lib/libcrypto.0.9.8.dylib" (file not found).
Debugger stopped.
Program exited with status value:45.
The killer is that the app installs, launches, crashes, and then launches fine manually. But I also can’t connect GDB to the running process after the fact either, GDB claims the process isn’t running. I have no idea what’s going on. Anyone?
UPDATE (8/3/10): Totally by chance I happened to read this article on TUAW today about FaceTime. I didn’t pay much attention until about half way down something caught my eye:
…rather significant My3G bug — when installed, you cannot use your iPhone for native software development….
I had initially thought that maybe third party software was to blame but I meticulously disabled each MobileSubstrate extension I had one at a time and ruled them all out. Turns out that wasn’t good enough. The (since fixed) My3G bug was exactly the source of this issue, but I had actually uninstalled My3G and the problem persisted. The issue, it turns out, is with the status bar library Intelliborn uses in their products, IntelliStatusBarIcons. BUT, it doesn’t stop there. By individually uninstalling apps, I’ve found that Backgrounder (and NOT libstatusbar) also cause a dealbreaking bug. Instead of the program exiting with status:45, the new error is “Program received signal: “SIGUSR1”. at which point the application hangs. Conveniently, the workaround is easy, if annoying: For your particular project title, add an Override in Backgrounder. Hopefully this IS a bug in Backgrounder and not a byproduct of its function. But at least now you can debug again!
So partly I’m dumb and partly this is just a bummer. Full story in this post, but the general idea is that gdb catches a SIGUSR1 from Backgrounder and you have to ‘continue’ through it. And obviously, disabling Backgrounder for your app prevents the signal from getting sent.
As awesome as always my friend!
[…] There's a new method for iOS4 but they're pretty similar […]
Thank you very much – worked in 5 minutes flat!
I’ve tested this with my iPhone 4 and it works fine. The only issue is that it always asks to install a provisioning profile when i debug on the device.
So after that one can’t use Xcode to develop normal iPhone Application. I mean the application need to be released to App Store. Right?
May be I should have to machine one for Jailbroken iPhone the other for Non JB iPhone.
I don’t actually know that that’s true. Maybe it is, but I can’t test it. But I think all you’d have to do is configure signing with your official identity like you normally would.
I made a bash script that is a bit easier to use than does gen_entitlements.py, you only need to put “exec /Developer/usr/bin/codesign.sh” in New Run Script Build Phase.
The script at /Developer/usr/bin/codesign.sh is the following one:
#!/bin/sh
#
# Code Signing for Jailbroken iPhone OS 4.0.1 and Xcode 3.2.3
#
if [ “$PLATFORM_NAME” == “iphoneos” ]
then
PRODUCT_IDENTIFIER=$(sed -n -e “s|\(.*\).\${PRODUCT_NAME:rfc1034identifier}|\1|p” $PRODUCT_SETTINGS_PATH).$PRODUCT_NAME
printf “\n\n\n\n\tapplication-identifier\n\t%s\n\tget-task-allow\n\t\n\n\n” $PRODUCT_IDENTIFIER > $TEMP_FILES_DIR/$PRODUCT_NAME.xcent
export CODESIGN_ALLOCATE=”$PLATFORM_DEVELOPER_BIN_DIR/codesign_allocate”
codesign –force –sign “iPhone Developer” –entitlements $TEMP_FILES_DIR/$PRODUCT_NAME.xcent $CODESIGNING_FOLDER_PATH
fi
Remember to make it executable with:
chmod 755 /Developer/usr/bin/codesign.sh
Only the self-signed certificate common name is hard coded in the script (“iPhone Developer”), it gets the application identifier (ie. com.mycompany.FooBar) from the product settings file (Info.plist), also it doesn’t put the entitlements file (.xcent) in the application directory.
It works fine on OS X 1.6, Xcode 2.2.3 and iPod touch 2G iOS 4.0.1 (jailbroken, AppSync 4.0 installed, and removed MobileSubstrate to avoid weird “file not found” errors). On the OS X side, I only had to edit:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/SDKSettings.plist
/Developer/Platforms/iPhoneOS.platform/Info.plist
Following the above instructions. There’s no need to patch (crack?) the Xcode Plug-in “PhoneOS Build System Support.”
Oh, the script codesign.sh doesn’t show correctly (the xml tags were removed :-S).
OK, here goes again, removed all the “” chars (but one), hope it works now:
#!/bin/sh
#
# Code Signing for Jailbroken iPhone OS 4.0.1 and Xcode 3.2.3
#
if [ “$PLATFORM_NAME” == “iphoneos” ]
then
PRODUCT_IDENTIFIER=$(sed -n -e “s|.string.\(.*\).\${PRODUCT_NAME:rfc1034identifier}./string.|\1|p” $PRODUCT_SETTINGS_PATH).$PRODUCT_NAME
printf “\x3c?xml version=\”1.0\” encoding=\”UTF-8\”?\x3e\n\x3c!DOCTYPE plist PUBLIC \”-//Apple//DTD PLIST 1.0//EN\” \”http://www.apple.com/DTDs/PropertyList-1.0.dtd\”\x3e\n\x3cplist version=\”1.0\”\x3e\n\x3cdict\x3e\n\t\x3ckey\x3eapplication-identifier\x3c/key\x3e\n\t\x3cstring\x3e%s\x3c/string\x3e\n\t\x3ckey\x3eget-task-allow\x3c/key\x3e\n
\t\x3ctrue/\x3e\n\x3c/dict\x3e\n\x3c/plist\x3e\n” $PRODUCT_IDENTIFIER > $TEMP_FILES_DIR/$PRODUCT_NAME.xcent
export CODESIGN_ALLOCATE=”$PLATFORM_DEVELOPER_BIN_DIR/codesign_allocate”
codesign –force –sign “iPhone Developer” –entitlements $TEMP_FILES_DIR/$PRODUCT_NAME.xcent $CODESIGNING_FOLDER_PATH
fi
Sorry the code doesn’t exactly come through. You might try http://pastie.org
guys sorz if u think its weird i donno this
im new to mac so not gd at editin stuff in it i did everything untill step 4
im stuck at step 5, wot “cd ~/Desktop” mean?
and also “vi script”
it says hit “I” i donno where i press it lol
sorz im just a newbie for mac
im ok intill step 4 cause all u do is open the file it says in text edit and change them
and wot does pastie do? i tryed it but all it does is just repeat wor u paste lol meaby i donno how to use it properly
Man, are you sure you understand what you’re trying to do? The pastie link was for ChaCha, his code wasn’t posting properly in comments because WordPress scrubs certain characters unpredictably.
sorz i just noticed u have to all this stuff in terminal lol anyway
im stuck somewere else now
after i press i, copy/paste then stuff, it says i have to press :x(enter) when i do tat it doesnt do anything but type tat in and go to next line after pressing enter
vi has two modes, command and insert (ok, there are more than just those). It loads in command mode, where typing a colon brings up a command prompt, and x is the command for “save and close.” typing just i (without a colon) puts you in insert mode, and in insert mode, typing escape puts you in command mode. So from in insert, type
tat angru sign was ment to be : X
ohh thx i thought i put those colons in to point out wot to press as it usally is lol
u*
sorz im such a noob but when i press 😡 in insert mode nothing happens it just types it in doesnt get out of insert mode :s
You also have to hit enter to send the command.
when i press enter it goes into the next line
You can try just editing those files with textedit.
how do i do tat?
where is the file located and where do i add it and stuff
ohh i got it now u missed a step
after u paste tat u press Esc to exit insert mode AND THEN press 😡
edit it so other ppl dont have to go through this trouble 🙂
Sorry, that’s what I meant when I explained command/insert mode. I wonder if I can turn the smilies off, kind of inconvenient for code.
ohh well im not a expert on mac or editing system files lol
thx for ur time 🙂
and also turn tat “reCAPTCHA” thing off its not like a blink person wout be using a computer or doing complicated stuff LOL
shit i just found out the version of sdk i have doesnt support my ios which is 4.01 if i upgrade it do i have to repeat any of the steps?
Most of them, yes.
ohh 🙁
can u tell me which 1’s exactly? all of then or can i skip 1 or 2?
Pretty much all of them except signing identity creation.
ohh thx
now tat i know how to do it in wont be long :/
hi i did everything and at the end when i select device and click build and debug i get 1 error
iPhone Developer: this identity cannot be used for signing code
Command /bin/sh failed with exit code 1
i think its the last thing u said to do where u have to do it for every app
Possible, but it’s more likely you didn’t properly do the “create a self-signing identity” step. Make sure to check “code signing” and only that on the second screen.
I’m getting ‘No provisioned iPhone OS device is connected’
Xcode 3.2.3
iPhone 3g with 4.0.1 Jailbreakme.com’d
any ideas ?
Did you actually do step 8, open organizer, find your device, and select “use for development”? Just in case, did you restart at least Xcode after?
oh duh ! i had organizer just show the sidebar , didn’t see the error about not having the right SDK , i guess in installed Xcode 3.2.3 with iOS 4.0 SDK . silly me . downloading now 🙂
works now ! thank you so much
I following the all steps and failed with “No provisioned iPhone OS device connected.”
My environment stats: Snow Leopard 10.6.4, xcode_3.2.3_and_iphone_sdk_4__final.dmg, iPhone 4 running 4.0.1
My XCode 3.2.3’s organizer tell me it don’t support 4.0.1 (8A306) on iPhone 4.
Any idea?
Now THAT’S odd. I assume you tried restarting? I can’t think of what it would be since your versions are all correct.
[…] Developing for a Jailbroken iPhone A to Z (iOS 4.0.1) […]
Hi, Alex! Thanks for a fine write up, as always! I’m having success with building/debugging a sample app from XCode (SimpleClock builds/debugs fine for IOS 4.0), but when I try to build some of my 3.0 software projects that I’m now building for 4.0, problems quickly surface during execution of your signing script:
/Users/temp/Desktop/src/Pie Utilities/build/PieUtilities.build/Debug-iphoneos/PieUtilities.build/Script-246D582D1212E98B0086BE16.sh: line 2: /Applications: is a directory
Project name= PieUtilities
Project Dir= /Users/temp/Desktop/src/Pie Utilities
Built Products Dir = /Users/temp/Desktop/src/Pie Utilities/build/Debug-iphoneos
Action = build
Product Name = PieUtilities
Built products =
Wrapper Name =
/Users/temp/Desktop/src/Piesiasoft Utilities/build/Debug-iphoneos//: object file format invalid or unsuitable
On my system, many of the variables don’t seem to be defined when the script is executing (notice the two forward slashes at the end before object file format invalid that are part of the problem).
This script is actually found in /Users/temp/Desktop/src/build/PiesiasoftUtilities.build/Debug-iphoneos/PiesiasoftUtilities.build (this is because all of my source code and source binaries are under svn source control, and I am trying to keep all of the object and executable code separate from this ). If I run the script in this directory, it seems to run just fine, it is the bad path to it that causes the problem.
Please note that in my project settings, I have in General, Place build products in custom location:
/Users/temp/Desktop/src/Piesiasoft Utilities/build
and General, Place build intermediate files in
Build products location
However, even if I reset these to defaults, and do a complete clean and rebuild, xcode acts as if I never changed these settings!
Do you have any suggestions as to how I might modify your script to get it to use Custom Locations?
Thanks very much! P.
The script on disk is:
/Users/temp/Desktop/src/build/PieUtilities.build/Debug-iphoneos/PieUtilities.build
Mac:PieUtilities.build temp$
cat Script-246D582D1212E98B0086BE16.sh
#!/bin/sh
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
the one in XCode under Targets, Run Script is:
/* 4.01 XCode provisioning script — Project > New Build Phase > New Run Script Build Phase */
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ “${PLATFORM_NAME}” == “iphoneos” ]; then
echo “Project name=” ${PROJECT_NAME};
echo “Project Dir= ” ${PROJECT_DIR};
echo “Built Products Dir = ” ${BUILT_PRODUCTS_DIR} ;
echo “Action = ” ${ACTION};
echo “Product Name = ” ${PRODUCT_NAME};
echo “Company name = ” ${COMPANY};
echo “Built products = ” ${BUILT_PRODUCTS};
echo “Wrapper Name = ” ${WRAPPER_NAME};
/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
thanks! P.
Thanks for the article!
I’ve got a problem, though: XCode builds the application just fine, but when it tries to transfer the app to my iPhone 4, I get the following message:
“The identity used to sign the executable is no longer valid. Please verify that your device’s clock is properly set, and that your signing certificate is not expired. (0xE8008018).”
The clock is set correctly, and the certificate is valid for another year since I created a new one.
Did I miss something? Any ideas?
To answer my question: After going through it all again, it seems that Cydia messed up on the AppSync part. Now it’s working fine. 🙂
@Frank i had the exact same problem , download the latest SDK from Apple , it supports 4.01
@coderneedsfood Thanks. I’m using ios sdk 4.1 beta 3 and it works.
A small question: when I install the application via itunes or to organizer, this one works, but when I copy the .app file in /private/var/stash/Applications (for cydia), it does not work.
Have you an idea?
thx
When you say “it does not work” do you mean “it doesn’t show up on the springboard”? When you manually copy apps via SSH, you have to respring for them to appear.
The application appears on the springboard but not execute not
it’s good , I had not put the permissions 775 has every file … ;p
Yep, that would do it 🙂