I was interested in exploring iOS development, but was not committed yet to serious development to justify paying $99 annually for the iOS Developer Program membership. So I searched for ways to to test my simple applications on my iOS devices without the extra costs.
Few months after writing this article, I found found myself more into serious iOS development, and subscribed to the iOS Developer Program. I wrote an article about my journey form learning iOS development to releasing Apps to the App Store.
In WWDC’15, Apple announced the new features of Xcode 7, which allows any developer with just and Apple ID (without having to purchase Developer membership) to test on physical devices!
Thanks to Adam for sharing this in the comments area.
Here is a link for the steps to do it on Xcode 7.
so starting from Xcode 7, you don’t have to do any of the steps below to test on your device
After many experimentation, I settled on the procedure described in this post, which I tested with the following combination of versions:
- Xcode 4.6
- Mac OS X Lion (10.7.5)
- iOS 5.1.1 (on my iPad)
- iOS 6.1 & 6.1.2 (on my iPhone 4)
It may work with other versions of Xcode and iOS, but I’ve just tested the above combinations.
Many of our readers have tried different versions, and sometimes modified the procedure to work on them. The comments are full of their experience.
The following couple of links helped me the most:
The procedure can be summarized in the following main steps, which we will explain in more details below:
- JailBreak the iOS Device
- Prepare iOS Device to allow installing Apps with self-signed certificates
- Connect iOS Device to Xcode and configure to use it for development
- Create self-signed code-signing certificate in Keychain Access
- Configure Xcode to allow using self-signed code-signging certificate
- Configure Xcode to allow debugging on the iOS Device
1. JailBreak the iOS Device
This step is a prerequisite to allow developing on your iOS Device without the provisioning profile. If not jailbroken, then the only way to develop on it is through the iOS Developer Program membership (which cost $99 annually)
So, you need to search for the jailbreak steps for your specific iOS version. For example, I’ve followed the steps in the link below to jailbreak my iOS 5.1.1 iPad:
2. Prepare iOS Device to allow installing Apps with self-signed certificates
Jailbreaking the iOS Device is not enough to have Xcode to deploy and debug applications on it. We need to do ONLY ONE of the following techniques:
- Connect using ssh to the iOS device and create empty file named (/var/mobile/tdmtanf)
- This technique works only with iOS versions 4.x to 5.x (I’ve tested on iOS 6.1 and it didn’t work).
- You first need to install OpenSSH form Cydia to allow SSH connections.
- don’t forget to change root password from the default value (“alpine”) set during jailbreak.
- run this command to create the empty file:
$ touch /var/mobile/tdmtanf
- Install AppSync application from Cydia
- If the first technique does’t work, then we can go with this one.
- I don’t know if there is any version limitation to use this technique. I tested it on iOS 5.1.1 and iOS 6.1.
- This application is not available in the standard Cydia package sources. I first had to add “repo.hackyouriphone.org” to package sources before finding the application on Cydia.
3. Connect iOS Device to Xcode and configure to use it for development
- Start Xcode.
- Connect the iOS Device using USB Cable.
- Open the Organizer window in Xcode (by selecting “Organizer” form the Xcode “Window” menu).
- Select the connected iOS Device in the navigation list on the left
- Click “Use for Development”.
- It will try to login to the Developer Account to check for provisioning profile. But since we don’t have one, then we just click “Cancel” in the login prompt.
- Every time we connect this iOS Device, it will be recognized to be used for development.
4. Create self-signed code-signing certificate in Keychain Access
- On your Mac, open the Keychain Access application.
- From the “Keychain Access” menu, select “Certification Assistant -> Create a Certificate”.
- In the first page of the wizard, fill in the following data then click “Continue”:
- Click “Continue” for the confirmation message to create self signed certificate.
- Change Validity Period as needed (e.g. make it 3650 for 10 year validity!), then click “Continue”.
- Blank the Email Address field, then click “Continue”.
- Accept the default for the Key Size and Algorithm, then click “Continue”.
- Keep clicking “Continue” accepting the defaults for next pages until you get the option to click “Create”.
- Click “Create” then click “Done”.
5. Configure Xcode to allow using self-signed code-signging certificate
- Close Xcode if it’s open.
- Open the terminal application and run the following commands (paths may be different for different versions of Xcode. The below is at least valid for version 4.6).
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform $ # create copy of Info.plist $ sudo cp -p Info.plist Info.plist.orig $ # convert to editable xml format $ sudo plutil -convert xml1 ./Info.plist $ # replace each occurrence of CiPhoneOSCodeSignContext with XCCodeSignContext in Info.plist $ sudo sed -i .bkup 's/XCiPhoneOSCodeSignContext/XCCodeSignContext/g' ./Info.plist
- Start Xcode.
- Open an iOS project of your choice, or create a simple one from templates (e.g. “Single-View Application”).
- Make sure the ‘iPhone Developer” certificate is select in the “Code Signing Identity” setting in the project Build Settings.
- Select the connected iOS Device form the list besides the Run button.
- Click the Run button, and Xcode should be able to deploy the application into the connected iOS Device. It will just confirm to allow using the self-signed certificate that we created earlier.
- It will fail to start the application for debugging (we will take care of this later in this post).
- We can still manually run the application by clicking its icon on the home screen of the iOS Device.
6. Configure Xcode to allow debugging on the iOS Device
- Close Xcode if it’s open.
- Obtain a copy of “ldid” utility and place in “/usr/local/bin” directory (it can be any other directory, but some of the steps below assumes this path). We can obtain ldid utility either by:
- Create a script called ldid3.py in the same path we put ldid (i.e. “/usr/local/bin” in our example). The script contains the following. (The ldid3.py is also included in the same zip file on my dropbox.)
#!/usr/bin/env python from sys import argv from subprocess import check_call from os.path import basename, dirname, splitext, join from tempfile import NamedTemporaryFile app = argv[-1] ldid_path = join(dirname(__file__), 'ldid') obj_path = join(app, splitext(basename(app))) if '-gta' not in argv: check_call([ldid_path, '-S', obj_path]) else: with NamedTemporaryFile('w+b', 0) as f: f.write(""" <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>get-task-allow</key> <true/> </dict> </plist> """) f.flush() check_call([ldid_path, '-S' + f.name, obj_path])
- make sure both “ldid” and “ldid3.py” are executable.
$ sudo chmod +x /usr/local/bin/ldid $ sudo chmod +x /usr/local/bin/ldid3.py
- Update iPhoneCodeSign.xcspec file following the commands below. The file path here is for Xcode 4.6. We can refer to the reference article for other versions.
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications $ # create a backup copy of iPhoneCodeSign.xcspec $ sudo cp -p iPhoneCodeSign.xcspec iPhoneCodeSign.xcspec.orig $ # convert to editable xml format $ sudo plutil -convert xml1 iPhoneCodeSign.xcspec $ # replace /usr/bin/codesign with /usr/local/bin/ldid3.py $ sudo sed -i .bkup 's/\/usr\/bin\/codesign/\/usr\/local\/bin\/ldid3.py/g' iPhoneCodeSign.xcspec
- Start Xcode.
- To enable debugging, we need to add “-gta” to the “Other Code Signing Flags” in the project Build Settings. Otherwise, debugging will not work (note the check for “-gta” in the python script we created earlier).
- Built and run your application, and debugging should work this time!
Finally, I hope the procedure explained above has helped you to explore iOS development as I did. When it’s time for serious iOS development, then the iOS Developer Program membership is indispensable.
I myself went through this experience, and when I found myself more into serious iOS development, I subscribed to the iOS developer program. I wrote an article about my journey from learning to releasing Apps to the App Store.