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.
Anyone who knows how to solve this:
The Info.plist for application at /Users/xxxxxx/Documents/Untitled/build/Debug-iphoneos/Untitled.app specifies a minimum OS version of 4.1, which is too high to be installed on xxxx
I can’t get it to work on my device
Right. The problem is exactly what it told you :). In your project, you have minimum OS version set to 4.1, probably because you downloaded and installed the 4.1 SDK and that would naturally be default, when your device only has OS 4.0.1 on it, since you can’t jailbreak 4.1 yet (at least on most devices). All you have to do is set the minimum OS version project setting to 4.0.1. Or even manually edit that .plist to reflect that.
It worked. thank you
It doesn’t work on the iOS SDK 4.1 for me. I get these errors: iPhone Developer: this identity cannot be used for signing code
Command /bin/sh failed with exit code 1
I DID make a certificate with the name iPhone Developer in my keychain
Hey Alex,
First up, thanks a Trillion for this guide! 🙂
Works very well in iPad (iOS 3.2.1) with Xcode 3.2.3, only one change is necesary. Is a obvious change 🙂
In step 3 line 1 change
cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
with
cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk
thanks for all
Thanks !
This eventually works on my iPhone 4 (with a jailbroken iOS 4.0). Read the tutorial carefully, regenerated the certificate, and everything is perfect, even debugging.
Does it work also on the 4.1 sdk? if not, where can I download the 4.0 sdk?
Obviously, on my iPhone I have 4.0.1 installed since it is jailbroken.
Hi all,
any one try to sdk4.0 please help me
Stuck at step 5. When I copy and paste the code into Terminal and follow the resulting steps, nothing happens and pressing enter just moves the cursor down without running the script?
Same problem as Vincent.. How can i fix this?
@Vincent & Giel : After pasting the code in vi, you need to first hit “esc”, then “:” then “x”. At least that is what I think is the problem here.
@Author: Thanks a ton, have been looking for this kind of information for a while now.
@mrwoody It’s working perfectly on my iPod Touch 2G with iOS 4.1
Hey your tutorial is Exelent!
Worked for me for an iPhone 4 iOS 4.0
The debugmode does not work for mi, but it’s ok until Apple gives me the license
Eventually got the script to work by entering it manually, but I still have one build error:
/Users/Vincent/Downloads/iPhoneCoreDataRecipes/build/Recipes.build/Release-iphoneos/Recipes.build/Script-BFF4C62E12543E45001DF631.sh: line 4: /Developer/iphoneentitlements401/gen_entitlements.py: Permission denied
Everything else, including the CodeSign worked fine, there’s just something up with the script?
Hey! Thank you very very much for your guide! It works perfectly with newest iPhoneSDK + Xcode Version! Love your work and your input!
Keep on doing your stuff. You are damn good at it!
Greetings
Heys…at step 7 I am stuck with curl: (6) Couldn’t resolve host ‘www.alexwhitemore.com’. Anyone knows what’s wrong?
sorry screw that, I found the typo. Using a ipod touch running on iOS4.0, all steps were carried out smoothly, but at the end, it says, \code signing is required\
[…] Credit: Most of the instructions are obtained from this website. […]
This works for me on an iPhone 4 and I have less than a day’s experience developing on iOS. Two things which slowed me down:
1. When creating the certificate in Keychain Access, be sure to have
name: iPhone Developer
Certificate Type: Code Signing
If you want to remove the script at the end for some reason: in the main window of XCode > Groups&Files > Targets > ProjectName > Run Script > delete it
2. This one is for neophytes like myself: if your phone is running iOS 4.0 and you’ve just downloaded XCode the settings will be set for 4.1 devices, to fix this:
Project > Edit Project Settings > Build > Deployment > iOS Deployment Target > set to iOS 4.0 or before
Build and run the Debug version opens the app on my device and works, I’ve yet to learn how to use the debugger. Thanks for the tutorial, it’ll make developing a lot funner.
it worked for me!
Thanks a lot!
This is great. It just works with Xcode 3.2.4 with iPhone 3GS 4.0.1 (jailbreak) with device set to 3.2 (change 4.0 to 3.2 in step 3 above). Thanks.
how to change in terminal????
CODE_SIGNING_REQUIRED
YES
and change YES to NO
then find
View Raw Code?
ENTITLEMENTS_REQUIRED
YES
and change YES to NO again. HINT: in vi, you can type the ‘/’ key in order to “Cmd-F”
Man this worked to me ;-D THANK YOU!
My iPhone is 4.0.1 and I installed 4.1 SDK so I spend a lot of time until reading the rgr comments and changed IOS Deployment Target to 4.0.
Now I`m a happy device developer!!!
everything works good but when i press bulid&run i get an error:
Command bin/sh failed with exit code 1
Can anyone help me?
Works like a charm with XCode 3.2.4, IOS 4.1, iPhone 3g
Labra: I encountered that error too. Check if your Certificate name is \iPhone Developer\ and if that’s the one selected in the project settings for the code signing (I had Don’t sign) when the error occurred.
This is excellent! I finally got my project to build, but I am unable to get it to run on my device (3GS iOS 4.0.1) using build & go because I am running mac in a virtual machine (virtualbox, windows 7 client), which does not support USB connection to iPhone.
I can compile to a .app file in the build/release folder, but I’m not sure what to do from there. I see various tutorials for how to create a .ipa from that (download an existing .ipa file, replace the .app program file inside with your own, etc), but that ipa says “invalid ipa” (or similar) when I drag it into iTunes.
What I really want is a way to deliver my app ad-hoc to my own iPhone and friends’ (all jailbroken, and with AppSync installed). How would I do that after following this tutorial?
I solved my problem (see comment above).
Apparently I did something wrong the last time I tried to create the ipa. It was easier than I thought, following the instructions here: http://tungchingkai.blogspot.com/2008/09/how-do-you-create-ipa-file.html
Installing AppSync via Cydia takes care of the “patched MobileInstallation file” requirement.
I didn’t use an iTunesArtwork file, so I skipped the whole “Getting the iTunesArtwork file” step (the app just has a blank gray icon, which is fine for me for now, but it would be easy enough to add my own jpg file to the ipa (just remove the “.jpg” extension and call it “iTunesArtwork”). The tutorial is written assuming you’re using an icon from an app in the app store)
Also, I used my mac virtual machine to edit the Info.plist file because I couldn’t get the plutil program to work on Windows 7 (it complained about a missing dependency).
After following that tutorial, I just dragged & dropped the .ipa into iTunes and sync’d, and the app works 🙂 Obviously, I won’t have the luxury of live debugging in xcode, but I think that’s currently impossible over a virtual machine, and at least this gives me a chance to test the program on an actual iPhone.
Hello! This works with Xcode 4 too! Modified codes:
#!/bin/bash
cd /Xcode4/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 “\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
mkdir /Xcode4/iphoneentitlements401
cd /Xcode4/iphoneentitlements401
curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt
mv gen_entitlements.txt gen_entitlements.py
chmod 777 gen_entitlements.py
export CODESIGN_ALLOCATE=/Xcode4/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ “${PLATFORM_NAME}” == “iphoneos” ]; then
/Xcode4/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
[…] m’appuis sur deux blog en Français d’avril 2010 et en Anglais de août […]
[…] m’appuis sur deux blog en Français d’avril 2010 et en Anglais de août […]
Does anyone have an issue with running the iPad simulator after following these steps? I’m getting “dyld: Library not loaded: /System/Library/Frameworks/CoreMedia.framework/CoreMedia” followed by an EXEC_BAD_ACCESS crash.
It looks like the app won’t start because it’s looking for CoreMedia in the system libraries instead of the iPhoneSimulator libraries.
Hi,
I had followed these steps with my iPod Touch 2G (MC Model) with the firmware 3.1.2 and it worked just fine.
Now, I upgraded the iPod to 4.1 and Jailbroke it with GreenPo1son and got the last XCode SDK. I followed all the steps once again and i didn’t encounter any troubles except for a little problem with the Code Signing, and recreating the certificate solved it.
MY PROBLEM IS: Now, when I build any project in XCode directly in the device, the iPod reboots! The thing is that when it does, the app is installed and i can run it normally. The problem seems to emerge when the app is running from XCode to the device.
Has anyone had this problem before?
By the way, I forgot to mention in my above post, in the console i get this messages:
gdb stack trace at ‘putpkt: write failed’:
putpkt: write failed: Broken pipe
putpkt: write failed: Broken pipe
The program being debugged is not being run.
The program being debugged is not being run.
.
.
.
And at the end:
The Debugger has exited due to signal 15 (SIGTERM).
Any clues?
That’s interesting, for sure. I’ve upgraded and jailbroken my iPhone 4, but I haven’t tried this over again yet. Maybe this weekend I’ll have time. The only thing I can think of is that maybe loading the debugger causes some sort of a disruption to the userland hack currently used to untether the jailbreak, but that seems like a real stab in the dark.
Unfortunately, those messages aren’t elling you much. putpkt: write failed: Broken pipe means literally that: the connection to the iPhone was lost. That entire set of errors occurs whenever the connection to the debugging interface on the phone is lost, be that unplugging it or be that the program ending unexpectedly before or right after launch.
Hi there,
First all, thanks for the guide Alex. Really good described and easy to follow.
I’d like just to confirm the behaviour Luis M was describing. I follow all steps for an iPod Touch 2G MC model jailbreaked with greenpois0n. Cydia installed and next AppSync. I follow all the steps without problems, but when I build and run, the ipod just reboots. When it’s back, the app is on the ipod.
Working Perfectly on XCode 3.2.4 and iPod Touch Gen 4 iOS 4.1
I can confirm the reboot behavior too. iPhone 3G, iOS 4.1, jailbroken. After reboot, app’s there and works without problems.
I keep on getting Command /bin/sh failed with exit code 1 error! And i have the build settings set to don’t code sign and everything. Please what is up?
Some more info about the reboots.
Just tried to launch the app on the ipod and next attach the debugger. I got the same result, device reboots… 🙁
Confirming reboot problem on iPhone 3G, FW 4.1, SDK 4.1. I guess we’ll just have to debug from the simulator till this is worked out.
A small update, it seems its not the debugger causing the issue. I just built for release so as not to start the debugger and it still rebooted. It reboots right after XCode tells the iPhone to start the application.
Nigel, try to start manually from the iphone and to attach later the debugger. It also reboots.
For me, it looks like it reboots when the computer connects for anything to the ipod.
Much older fw/versions but same issue here… http://www.hackint0sh.org/f9/111232.htm
Looking into the script who signs the app, I see an extra parameter passed to codesign. –resource-rules and some plist.
Could this have something to do? I cannot test now, will do later.
Hi everyone and thanks for the guide ^^
I can’t either debug or release on my iphone. I’m using iPhon 3g iOS 4.1 (jailbroken and with AppSync) and Xcode 3.2.4. Everything went ok but when I try to build and run I got this error:
Debug:
Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.HelloWorld’ could not be found
I created a certificate named “iPhone Developer” following the guide suggested so… I’m not sure what’s going on. On Project settings I can see “Code Signing Identity(Any iOS Device) = iPhone Developer”.
Any idea? Thanks!
I forgot, in release mode I get 1 error, 3 warnings:
/Developer/iphoneentitlements410/gen_entitlements.py: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf320: command not found
/Developer/iphoneentitlements410/gen_entitlements.py: line 2: syntax error near unexpected token `}’
/Developer/iphoneentitlements410/gen_entitlements.py: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;}’
/Users/miggat/Documents/xCode Projects/HelloWorld/build/Release-iphoneos/HelloWorld.app/HelloWorld.xcent: cannot read entitlement data
Command /bin/sh failed with exit code 1
Validate build/Release-iphoneos/HelloWorld.app
cd “/Users/miggat/Documents/xCode Projects/HelloWorld”
setenv PATH “/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
setenv PRODUCT_TYPE com.apple.product-type.application
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/Validation “/Users/miggat/Documents/xCode Projects/HelloWorld/build/Release-iphoneos/HelloWorld.app”
warning: iPhone/iPod Touch: Info.plist: Unable to verify icon dimensions, no icon found. You must define CFBundleIconFile, CFBundleIconFiles, or provide a default Icon.png that is 57×57 (-19013)
Unable to validate your application. – (null)
warning: Info.plist does not contain a CFBundleResourceSpecification (-19015)
Unable to validate your application. – (null)
warning: Application failed codesign verification. The signature was invalid, or it was not signed with an Apple submission certificate. (-19011)
failed to extract requirements data: 1
/Users/miggat/Documents/xCode Projects/HelloWorld/build/Release-iphoneos/HelloWorld.app: code object is not signed
failed to extract entitlements: 1
– (null)
It worked for me using XCode 3.2.4 iPhone 3g with Firmware 3.1.2
I had problems with that xcode shows an error related to “code signing”. I hadn’t marked the certificate as “trust always”
intructions here:
http://pastie.org/1078299
It works great, but it doesn’t actually start the application, it just installs it and then says finished running (so you can’t debug on device). Is there any way to fix that?
Adev, you saved my life! Thanks for the pastie. And thanks alex for the awesome tutorial!!
[…] poddali i coś stworzyli i tworzą dalej Podaje link do strony (strona w języku angielskim) : Developing for a Jailbroken iPhone A to Z (iOS 4.0.1) � alexwhittemore.com Daje tez załącznik z skryptami (polecam rozpakować to na pulpit waszego blaszaka hehe […]
Is there any tutorials for 4.1??