Testing Your iOS Apps on a Jailbroken Device

The route Apple would have you take, and the route you should take if you intend on publishing your app all the way to the appstore is buying an Apple Developer Certificate (which costs about 99$ a year). With it you’ll get to develope, test and distribute your apps on the AppStore. You also get access to a whole load of really awesome resources.

BUT……. If you have a jailbroken device AND if you’re like me, then you’ll wanna debug your case studies and demo apps on your iPhone and not shell out the dough till you actually decide to distribute your app :P  (Lets say its the Indian blood in me that rebels against paying for something that I could get for free). So I’ve decided that I have to share this…

More after the Jump :)

Ok, I’ve basically used a mixture of 3 HowTo’s in this tutorial. We’re following the steps that Cawas outlined in his reply in StackOverflow. He in turn is following Jason’s and alex’s method. With the third we have the advantage of being able to debug. I’ll mostly just copy Cawas tutorial. However there’s a step at the end that I’ll add that will enable you to test your applications on any device (ie iPhone 3G onwards).

All the green text in this tutorial is to be entired directly into Terminal (of course :D )

Create Self-Signed Certificate

First you’ll need to create a self signed certificate and patch your iPhone SDK to allow the use of this certificate:

  1. Launch Keychain Access.app. With no items selected, from the Keychain menu select Certificate Assistant, then Create a Certificate.
    • Name: iPhone Developer
    • Certificate Type: Code Signing
    • Let me override defaults: Yes
  2. Click ContinueClick Continue
    Blank out the Email address field.
    • Validity: 3650 days
  3. Click Continue until complete.You should see “This root certificate is not trusted”. This is expected.
  4. Set the iPhone SDK to allow the self-signed certificate to be used :
    • sudo /usr/bin/sed -i .bak ‘s/XCiPhoneOSCodeSignContext/XCCodeSignContext/’ /Developer/Platforms/iPhoneOS.platform/Info.plist
  5. If you have Xcode open, restart it for this change to take effect.
Update 1 : For iOS 5
If I’m not mistaken, you don’t need to “Enable Xcode to Build on a JB device”…. As far as I know, after the first part the app should load on your device (even though it may not debug).

Enable Xcode’s to Build on Jailbroken Device

1. For below iOS 5 :

    • sudo /usr/bin/sed -i .bak ‘/_REQUIRED/N;s/YES/NO/’ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/ SDKSettings.plist

Update 2  :

For iOS 5 : Incase you do still want to go through the whole process the code in terminal that you type should be :

    • sudo /usr/bin/sed -i .bak ‘/_REQUIRED/N;s/YES/NO/’ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/SDKSettings.plist
2. On your jailbroken iPhone, install the app AppSync.
3. Remove SDK requirements for code sign and entitlements (I’m loving sed!):
    • sudo /usr/bin/sed -i .bak ‘/_REQUIRED/N;s/YES/NO/’ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/ SDKSettings.plist

4. Conclude the requirement removal through patching Xcode. This means binary editing:

    • cd /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS\ Build\ System\ Support.xcplugin/Contents/MacOS/
    • printf “\xc3\x26\x00\x00″ >> working
    • dd if=iPhoneOS\ Build\ System\ Support of=working bs=500 count=255
    • /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
5. If you have Xcode open, restart it for this change (and last one) to take effect.
6. 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”:alt text
After this feel free to undo stepAt least in my case it went just fine.

To Enable Debugging :

1. Setting Xcode to code sign with our custom made self-signed certificate (the first how-to). This step can probably be skipped if you don’t want to be able to debug:

2. 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.
3. Now 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

Make this work on ALL your iPhone devices :)

  1. Now, in order to make the app work on all your iOS devices (ie iPhone 3G onwards) you need to do the following for every project.
  2. XCode 4 automatically sets the projet archietecture to armv7 for every new iOS app created. However, you need to add armv6 to the required architectures list to support iPhone 3G. To do this, open the Target Build Settings and find “Valid Architectures”. Double click on the line and you’ll see a pop-up box appear. Delete the current architectures using the ‘-’ (minus) sign at the bottom and add 2 architectures : armv7 & armv6
  3. Hit Done. Now do the same in the Project Build Settings in the Project Editor menu. Change the Valid architectures to armv6 and armv7 as shown above.Done !! Now connect your iPhone and run the application on your device :)
About these ads

27 thoughts on “Testing Your iOS Apps on a Jailbroken Device

  1. Every time i try to run the code to Enable Xcode’s to Build on Jailbroken Device, i get this error:
    sed: -i may not be used with stdin
    -bash: s/YES/NO/: No such file or directory
    I am working on IOS 5.0 and i replaced it instead of 4.2if i go via terminal thru the path i can open the p.list via pico, but i don’t know what to replace, could you show me the light please
    Thanks in advance

    • For iOS 5
      If I’m not mistaken, you don’t need to “Enable Xcode to Build on a JB device”…. As far as I know, after the first part the app should load on your device (even though it may not jailbreak.

      Incase you do still want to go through the whole process the code in terminal that you type should be :
      sudo /usr/bin/sed -i .bak ‘/_REQUIRED/N;s/YES/NO/’ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/SDKSettings.plist

      Can you check that and let me know if it works :)

  2. Hey very cool blog!! Man .. Excellent .. Amazing .. I’ll bookmark your site and take the feeds also…I’m happy to find a lot of useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

  3. Hey I am unable to process any command here. The first command here:(sudo /usr/bin/sed -i .bak ‘/_REQUIRED/N;s/YES/NO/’ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/ SDKSettings.plist ) gives the error sed: 1: “‘/_REQUIRED/N”: invalid command code ?
    -bash: s/YES/NO/’: No such file or directory
    can you please help ?

  4. sudo /usr/bin/sed -i .bak ‘/_REQUIRED/N;s/YES/NO/’ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/SDKSettings.plist
    Password:
    sed: 1: “‘/_REQUIRED/N”: invalid command code ?
    -bash: s/YES/NO/’: No such file or directory
    getting stuck here could u pls help me out with dis???

      • Users/MacBookPro/Library/Developer/Xcode/DerivedData/Quiz_Game-doshnykxfahtwkegjllmbgpnpxwz/Build/Intermediates/Quiz Game.build/Debug-iphoneos/Quiz Game.build/Script-52914725158B5B5F00585385.sh: line 4: /Developer/iphoneentitlements401/gen_entitlements.py: No such file or directory “iPhone: no identity found…..been trying and slogging but i get dis error all the time cud u help me out with dis….

  5. Great work, well written and well done. Btw, do I need to this same procedure if I have a developer’s license and want to test on a jailbroken iPad 1?

    • No sorry :( no other way. Also I don’t think that iOS 7 has been jailbroken yet, so you may have to wait a while.

      Best Regards Sasha Azad

      - sent from my iPhone

  6. Pingback: Important links for beginning development of iOS Applications | Sourabh's space

  7. Hi ,
    After I have created self-signed certificate , I have set Iphone Sdk and I have received the next error in terminal:
    sed: 1: ” `s/XCiphoneOSCodeSign… ” : invalid command code ?

    Can you inform me what is wrong ?

    Thank you ,

  8. Hi nice post, i hope u can help me
    I have received the next error in terminal:
    sed: /Developer/Platforms/iPhoneOS.platform/Info.plist: No such file or directory
    I used iphone 5 with iOS 7.0.4 with jailbreak
    what is wrong?

Leave a message :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s