apple of my i

Musings of an Apple fanboi

Developing on jailbroken iPhone 4S (5.1.1) with Xcode 4.4.1

First of all, the intent of this post is not to discourage iOS developers from creating a $99/yr developer account. Ultimately, all serious developers would and should. This post is meant to assist hobbyists or budding developers in their initial experimentation with a jailbroken iPhone to run their own apps.. at least until the time they get into serious iOS development. If you’re an Apple developer, chances are you love Apple and so, don’t do anything that harms Apple or the eco-system (includes developers).

The post is an update to http://www.alexwhittemore.com/developing-jailbroken-iphone-ios-401/. I sincerely thank Alex for writing a detailed post that helped me in successfully running my test apps, developed under Xcode 4.4.1 on Mountain Lion with my iPhone 4S (5.1.1). As I discovered, there were a few (minor) changes required for 5.1.1 on Xcode 4.4.1 since the original post was targeted at an older version of iOS (4.x) and Xcode.  I sort of struggled to get a definitive guide anywhere on the Internet, and many stated methods just don’t work with 5.1.1. If you notice any technical errors in the post or have suggestions, please add a comment or feel free to write to me at v dot tmp at me dot com.

Essentially, there are 10 broad steps to accomplish this task. I’m not providing detailed descriptions of these steps here and assume that you understand most of it—you’re a developer after all.  If you need further clarity, do refer to the original post by Alex Whittemore.

            1. Jailbreak your iPhone 4S

              You can follow the instruction at the Greenpois0n site for jailbreaking your iPhone 4S (5.1.1). Works like a charm.. but do take a backup!
            2. Install AppSync for iOS 5.0+

              Open Cydia, and add http://cydia.hackulo.us as a source. I installed version 2.2 by Dissident.

            3. Create self-signed certificate

              Using Keychain Access create a self signed certificate with the name ‘iPhone Developer’. I guess other names should work as well but I just went with whatever has been mentioned in documentation elsewhere.

              Please wait for images to load below:

              Choose “Create a Certificate” using Keychain Access

              Select certificate name as “iPhone Developer”; type - “Code Signing”

              Specify a large validity period for your certificate

              You don’t have to put your email address there

              Default

              Default

              Default

              Default

              Default

              Default

              You should see “iPhone Developer” here

              Click on this certificate, you’d see something like (next slide)

              Verify your certificate details


              Before we move to Xcode related changes, here are  some suggested books for iOS development from Amazon[Advertisement]:


              Xcode Books:

            4. Modify Xcode plist files

              Close Xcode and change the following plist files for code signing and entitlement requirements

              • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/SDKSettings.plist

                Change

                <key>CODE_SIGNING_REQUIRED</key>
                <string>YES</string>

                To

                <key>CODE_SIGNING_REQUIRED</key>
                <string>NO</string>

                Change

                <key>ENTITLEMENTS_REQUIRED</key>
                <string>YES</string>

                To

                <key>ENTITLEMENTS_REQUIRED</key>
                <string>NO</string>
              • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Info.plist

                Change (twice)

                <key>CODE_SIGN_CONTEXT_CLASS</key>
                <string>XCiPhoneOSCodeSignContext</string>

                To

                <key>CODE_SIGN_CONTEXT_CLASS</key>
                <string>XCCodeSignContext</string>
            5. Patch Xcode 4.4.1

               
              # cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS\ Build\ System\ Support.xcplugin/Contents/MacOS/ 
              # cp ./iPhoneOS\ Build\ System\ Support ./iPhoneOS\ Build\ System\ Support.orig 
              # printf “\xc3\x26\x00\x00” » ./iPhoneOS\ Build\ System\ Support 
              # chmod a+x iPhoneOS\ Build\ System\ Support
              
            6. Modify code signing requirements in Xcode to “do not sign”

            7. Tell Xcode to code sign

              # mkdir /Applications/Xcode.app/Contents/Developer/iphoneentitlements511
              # cd /Applications/Xcode.app/Contents/Developer/iphoneentitlements511 
              # curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt
              # mv gen_entitlements.txt gen_entitlements.py 
              # chmod 777 gen_entitlements.py 
              
            8. Plug in your iPhone and configure for development

              Refer to Alex’ blogpost in case you’re not able to figure this out yourself.  I don’t even remember what I did.. but this wasn’t really an issue.
            9. Add a run script to your project build phase



              Here’s the exact script that you need to copy/paste.  A reader (Josh) reported some issues in copying/pasting this.. so get it from here (Thanks Josh) :

              export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate 
              if [ “${PLATFORM_NAME}” == “iphoneos” ]; then 
                 /Applications/Xcode.app/Contents/Developer/iphoneentitlements511/gen_entitlements.py “com.yourcompany.${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 
              
            10. Make sure your iPhone is still connected and unlocked. Build and test on your phone:

              Well, that’s it. Your app should be on your iPhone now.  Look on the second screen.
              NOTE: Make sure you don’t name your app the same as an existing one.. like Calculator :-).  I overwrote the original Calculator on my iPhone.  In fact, if one of you can share the Calculator.app with me, that’ll be great (5.1.1) please.

              I had tried the other (simpler) approaches before this - like ldid -S or sysctl one.. they don’t seem to work with 5.1.1.  Please let me know if you’ve got them to work.
              Happy coding!
  1. ivishal posted this


blog comments powered by Disqus