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.
Dude… YOU ROCK!
Worked first go without issue. 🙂
[iPhone 4, iOS 4.01]
[…] NOTE : this post is the exact copy of the following post : http://www.alexwhittemore.com/?p=398 […]
I have iPhone 3GS with 4.0.1.
Install latest SDK +XCode (name was something with 4.0.2), but I did NOT upgrade my phone.
Did all steps. Double check. Triple check. But when I click build I get 1 error:
iPhone Developer: this identity cannot be used for signing code
Command /bin/sh failed with exit code 1
Re-generate the certificate. On the second screen, you have to specifically select “code signing.” Unfortunately, the linked tutorial in the apple docs doesn’t agree exactly with the current interface as of OSX 10.6.
I’m new to the Mac OS. Can you please give me a hint how to Re-generate the certificate?
Thanks.
Follow this guide here
http://developer.apple.com/mac/library/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html#//apple_ref/doc/uid/TP40005929-CH4-SW1
but carefully read each screen knowing that you want to generate a certificate *for codesigning* (not email, the default). Specifically, launch Keychain Access (searching it in spotlight is easiest, type cmd-space to bring up the search box), and then find the menu item Keychain Access>Cert Assistant>Generate Cert to bring up the wizard. I think in 10.6, the second screen is where you select code signing. Fill in your personal info, and for everything else, defaults are fine.
OK. Did that. Same error message when I click build.
Do I need to choose my certificate in the Build/Code Signing Identity , or , Build/Any iPhone OS Device ???
My certificate did not help. I’ve changed it back to “Do not sign” (both of them).
Have no idea what I did wrong.
No, in fact you need to specifically select “don’t code sign” in those locations. Maybe that’s the issue? Did you make sure to delete the first certificate you generated before regenerating it?
I only have 1 certificate. I’ve set it to “don’t code sign” in both locations.
choose Device-Debug-Build and Run give error:
Run custom shell script ‘Run Script’
iPhone Developer: no identity found
!Command /bin/sh failed with exit code 1
Ahh, THIS time it’s because the certificate you generated was named improperly. Make sure it’s called, EXACTLY,
iPhone Developer
including proper capitalization.
Sorry this is not working out for you yet 😛
Ohh WOW. Sorry about that. Working fine now.
Thank you for all your help and fast response. Really appreciate it…
Hi Alex, thanks for such a great guide! I’ve always wanted to get into iOS development but was always hindered by the developer fees Apple demands. I wanted to develop apps for my own personal use, but I can’t take the iPhone Simulator with me everywhere 😉
Now that I’m finally getting into iOS development, you wouldn’t happen to know of any articles/guides that deal with porting UNIX utilities to iOS, would you? I’ve used many utilities that were originally designed for UNIX-based distros and ported to iOS, but haven’t been able to figure out what’s necessary to do so on my own. Thanks, and again, excellent guide!
Another error for me :
“iPhone Developer: this identity cannot be used for signing code”
I don’t understand because I did exactly the same thing as you.. :/
Sorry, all is okay thanks to this : http://pastie.org/1078299
hi alex! thanks for this great guide to develop on iOS4.
however I couldnt get things to work: I got the following warning when launching xcode at step 6:
“no device support package are installed”
When I go into the options, to first tell to xcode not to sign the code there is no “any iphone OS device” in the choices proposed by the combo box.
i guess i am missing some packages to run on actual devices? but I wonder why?
i googled around and saw that there is a problem with powerpc cpus but I am running a virtual machine wich shows an Intel core duo to the OS so that doesn’t seem to be related?
i downloaded Xcode from apple website by registering as a developper and I am beginning to wonder if the necessary packages are provided in this download.
If no, where is it possible to get a version of Xcode with the necessary packages to run on iOS4?
Thx in advance.
Hi Alex, please forget my previous comment, there’s something strange: actually when reverting the changes to info.plist and SDKsettings.plist, I can launch Xcode and see development options targetting the devices. I guess there must have been something wrong while editing the files, so I will re-edit the files to see if I can get it to work.
Hi Alex!
I could fix this by effectuating step 6 before editing plist’s files. I dont know what the real reason is, maybe because I didn’t lauch Xcode even once after the installation, without touching the config files. Or maybe because this time I also changed the SDKsettings,plist under “/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk”.
Anyway thank you very much to take a little time to write this clear guide! That was so helpful!
Haha, well, I’m glad you figured it out!
I made a video a while back about this, and full credit to this very blog is in the video description.
It contains a simple script you can download and run that will do this very same process and also install the default templates but patched already for you so you don’t have to do any extra steps for new projects!
Thanks again Alex, without you this video wouldn’t be possible.
FYI, as of 8/24/10, the latest My3G still causes the exited with status:45 issue. I have MyWi4+IntelliStatusBarIcons installed, and the apps debug just fine – but with My3G installed, they do not.
They HAD fixed it, and I think I tried a couple days ago with success, but maybe it’s been un-fixed. I’ll test again in a bit. Thanks for the heads up, though!
Leon, thanks a bunch! I was hoping you’d do up another script.
i have SDK 4.0 & my device is jailbreak with FW 3.1.3 ,when i want to set my iphone to “Use for development.” it crashes what should i do to have app that i can run it in to my device?
You probably don’t have the 3.1 sdk installed. Upgrade the device to 4.x or find and install the 3.x sdk. It might be on the dev center website still, but I’m not sure.
Hi Alex,
Thank you very much for your tutorial to get the app build and run on iPhone.
I got it built and run on my iPhone 3GS iOS4.0
My question is:
I already class-dumped all the private framework from iPhoneOS.platform and put in a folder. Then I add the folder path to the project setting under : Frameworks Search Path , User Header Search Path in Search Path section.
However, I still can not build my app, compiler complain that the header of private framework that i used: no such file or directory.
Why can’t I add user defined header that way? Is there any solution for this matter?
Thank you very much in advance.
Anh
This is just a wild stab, but are you using
import “myframework.h”
Or
import
? Try the opposite. Also how did you dump the headers? I’d like to also.
hi alex,
would like some help…
i can get pass 1st step: Make some Plist adjustments, starting with SDKSettings.plist
i cant change the setting:
CODE_SIGNING_REQUIRED
YES
to NO, so i change access to Read and Write, but still cannot change the settings.
the only way i can change it is, copy to desktop, change it, and copy back to folder. but having done this, my Xcode crash everytime it launches.
i am using sdk 3.1.3 with xcode 3.1.4.
did i left out something?
thx in advance
How did i dump header? Well, just download class-dump utility, google it, very easy to find, then dump all header, including frivate framework. I did it into a fold der in my home folder, not in /Development blah blah where xcode is. Does that matter?
I did #import , because header is still in folder privateFrameworkName.framework.
I can send you the script that dump all headers in corresponding frameworks recursively and the class-dump link to you later if you want to (i am curently out side, and on iPhone, can do much at the moment)
Sorry i hqd typo mistake
I did #import (privatFrameworkName/HeaderName.h) , well actually the bracket is < but your site does not allow i guess
I’ve successfully started debugging my app using this technique, but I’m stumped as to why the high res art I’ve been using for my iPhone 4 loads in the simulator but not when debugging the app on the device. I had assumed that the OS would load the art, but is it possible that this technique has altered the way the OS sees the device?
@ stefan : read this site> http://www.washington.edu/computing/unix/vi.html
Thank you, it worked!
Hey Alex,
First up, thanks a billion for this guide!
Now to the gritty stuff.
I have got everything working perfectly fine, however, when I copy the .app from the iPhoneOS-release folder and create it into a .deb and try and install via Cydia, I loose my fake code sign and have to ldid it manually.
Is there any way that buy building it into a .deb package I’m destroying the code signature?
If so, how can I keep the code signature?
[…] Hier der Link: http://www.alexwhittemore.com/?p=398 […]
Alex.. its taken me a long time to get this running… I mean AGES..
But the end result is..
1. MAC OS running in VMWarez on Windoze – 10.6.4 (all licensed ofcourse…….)
2. On my 4.0.1 JB iphone (3GS)
3. Using Xcode 3.2.3 and 4.0 SDK.
I am stoked!
Thanks for the great tute, now for the killer app.. LOL!! (like you havent heard that a billion times!)
Thanks again
-Noob
Alex, ok I jumped the gun.
Although I can deploy and run the app, I think i have an issue with debugging..
I haven’t played around alot with debugging, and I can set a debug point, however I have noted the following in the console that you may be able to advise regarding the “symbol” related errors..
Any advice would be greatly appreciated.
Thanks
-Noob
run
Running…
[Switching to thread 11523]
[Switching to thread 11523]
continue
warning: Unable to read symbols for “/Library/MobileSubstrate/MobileSubstrate.dylib” (file not found).
warning: Unable to read symbols for “/Library/MobileSubstrate/MobileLoader.dylib” (file not found).
2010-09-05 15:02:53.656 Hello eyePhony[1951:307] MS:Notice: Installing: com.yourcompany.Hello-eyePhony [Hello eyePhony] (550.32)
2010-09-05 15:02:53.910 Hello eyePhony[1951:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/Activator.dylib
warning: Unable to read symbols for “/Library/MobileSubstrate/DynamicLibraries/Activator.dylib” (file not found).
2010-09-05 15:02:54.207 Hello eyePhony[1951:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/Backgrounder.dylib
warning: Unable to read symbols for “/Library/MobileSubstrate/DynamicLibraries/Backgrounder.dylib” (file not found).
warning: Unable to read symbols for “/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0.1/Symbols/usr/lib/libsubstrate.dylib” (file not found).
2010-09-05 15:02:54.629 Hello eyePhony[1951:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/IntelliStatusIconsView.dylib
warning: Unable to read symbols for “/Library/MobileSubstrate/DynamicLibraries/IntelliStatusIconsView.dylib” (file not found).
2010-09-05 15:02:55.182 Hello eyePhony[1951:307] Initializing IntelliStatusBarIcons v0.93
2010-09-05 15:02:55.191 Hello eyePhony[1951:307] Initialized listener for icon updates
2010-09-05 15:02:55.300 Hello eyePhony[1951:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/SimulatedKeyEvents.dylib
warning: Unable to read symbols for “/Library/MobileSubstrate/DynamicLibraries/SimulatedKeyEvents.dylib” (file not found).
2010-09-05 15:02:55.521 Hello eyePhony[1951:307] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/libstatusbar.dylib
warning: Unable to read symbols for “/Library/MobileSubstrate/DynamicLibraries/libstatusbar.dylib” (file not found).
Program received signal: “SIGUSR1”.
Hi alex, ive followed your lovely tutorial, and i am no longer getting the code signing error message. so thanks a lot for that.
when i click build, i get a message that says
iPhone Developer: ambiguous (matches “iPhone Developer” in /Library/Keychains/System.keychain and “IPhone Developer” in /Users/Pavan/Library/Keychains/login.keychain)
How can i solve this? can someone please help. It would be greatly appreciated.
thanks in advance.
ok i just solved this. I went into keychain, went into keys and noticed i had more than one key named as iPhone Developer, i deleted all of them and deleted all certificates and started create a new certificate with the name of iPhone Developer and everything works well! YESS ive just run build and the app has successfully been installed on my iphone and i can now program for it!
Come to think about it, i remember last year me trying to follow a similar tutorial on being able to program for my phone without ACD (apple’s developer membership) and i was required to create an iPhone Developer certificate but that tutorial didnt work and i left the keys and certificates in place which is why it caused the ambiguous clash of names!
hope this will help someone in the future that may fall into a similar position as me.
Noob: That problem is addressed at the VERRRRRRY bottom of the post: Backgrounder sends a SIGUSR1 signal to an app to tell it to enable backgrounding. If backgrounding for all apps is turned on, this signal gets sent as soon as the app finishes launching, and the debugger stalls on it. All you have to do is click the “continue” button in any of the windows containing debugger controls (I think console, build results, debugger, so on). Alternately, disable Backgrounder temporarily for all apps or just your project.
PK: Sorry I didn’t notice in time to help, but congratulations!
Hey Everyone,
Anyone run into this error…
[ProjectName].xcent cannot read entitlement data
Works great for a iphone 3gs on ios 4.0. Thanks!
Has anyone tried with 3.2.4?
Thanks
Hi, just tried on SDK 3.2.4, that’s working perfectly.
Thanks for this tutorial !!
Just tested on new xcode 3.2.4 with iOS 4.1 and it works even without patching xcode!
Is it really required? I can debug and all, seams fully functional.
Thanks
It might not be necessary anymore. But how did you test on 4.1 with no jailbreak?
This way is SO AMAZING XD
but how I can do build binary for “release”??
[…] […]
Thank you soo much for this great tutorial!!! This helped me a lot!
Does this work for SDK 4.1 cuz nothing happens when i get to “type the keys, in order: “:” “x” “enter”” in step 5.
for the last script, when i build and run it says “Running 1 of 1 custom shell scripts…” and never stops. what do i do?