Difference between revisions of "Xcode"

From iPhone Development Wiki
Jump to: navigation, search
m (fixed path at 7. for Xcode 4.2)
(Update info for iOS 5...)
Line 1: Line 1:
Xcode is ''the'' IDE endorsed by Apple for iPhoneOS development. The latest version 3.2.1. It comes with the official iPhone SDK.
+
Xcode is ''the'' IDE endorsed by Apple for iPhoneOS development. The latest version 4.2. It comes with the official iPhone SDK.
  
 
== Developing without Provisioning Profile ==
 
== Developing without Provisioning Profile ==
 
To develop for the devices one should first obtain a provisioning profile by joining the iPhone Developer Program (which costs $99). However, some simple tricks can be used to make Xcode compile and debug on jailbroken devices without provisioning profiles.
 
To develop for the devices one should first obtain a provisioning profile by joining the iPhone Developer Program (which costs $99). However, some simple tricks can be used to make Xcode compile and debug on jailbroken devices without provisioning profiles.
  
These steps are only tested for Xcode 3.2.x and iPhone SDK 3.x. If for some reason you are stuck with Xcode 3.1.x, try [http://iphonesdkdev.blogspot.com/2009/06/use-xcode-312-to-build-sdk-30-app-to-30.html].
+
These steps are only tested for Xcode 3.2.x/iPhone SDK 3.x and Xcode 4.2.x/iPhone SDK 5.x. If for some reason you are stuck with Xcode 3.1.x, try [http://iphonesdkdev.blogspot.com/2009/06/use-xcode-312-to-build-sdk-30-app-to-30.html].
  
 
=== Compiling ===
 
=== Compiling ===
 
Performing these steps allows you to use Xcode to compile any applications and deploy it yourself.
 
Performing these steps allows you to use Xcode to compile any applications and deploy it yourself.
  
* '''1.''' Create a self-signed code-signing certificate on the “login” (default) keychain using Keychain Access<ref>Procedures can be found in http://developer.apple.com/mac/library/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html</ref>.
+
* '''1.''' Create a self-signed code-signing certificate with the name “iPhone Developer” on the “login” (default) keychain using Keychain Access<ref>Procedures can be found in http://developer.apple.com/mac/library/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html</ref>.
 
* '''2.''' Open <tt>/Developer/Platforms/iPhoneOS.platform/Info.plist</tt>
 
* '''2.''' Open <tt>/Developer/Platforms/iPhoneOS.platform/Info.plist</tt>
* '''3.''' Replace all occurrences of <tt>XCiPhoneOSCodeSignContext</tt> by <tt>XCCodeSignContext</tt>. There are three of them (XCode Version 3.2.4).
+
* '''3.''' Replace all occurrences of <tt>XCiPhoneOSCodeSignContext</tt> by <tt>XCCodeSignContext</tt>. There are three of them (XCode Version 3.2.4+).
 
* '''4.''' Save the file and restart Xcode.
 
* '''4.''' Save the file and restart Xcode.
  
Line 19: Line 19:
 
These steps are necessary for debugging, since the entitlement can no longer be inserted by performing steps 1 – 4. To actually debug your app, make sure you have add <tt>-gta</tt> to '''Other Code Signing Flags''' of your target.
 
These steps are necessary for debugging, since the entitlement can no longer be inserted by performing steps 1 – 4. To actually debug your app, make sure you have add <tt>-gta</tt> to '''Other Code Signing Flags''' of your target.
  
* '''5.''' Make sure you have ldid on your Mac<ref>If not, you can install from Fink unstable, compile it from http://svn.telesphoreo.org/trunk/data/ldid/, or just download http://code.google.com/p/networkpx/downloads/detail?name=ldid</ref>. Place a copy in <tt>/usr/local/bin</tt>.
+
* '''5.''' Make sure you have ldid on your Mac<ref>If not, you can install from Fink unstable, compile it from git://git.saurik.com/ldid.git, or just download https://github.com/downloads/rpetrich/ldid/ldid.zip</ref>. Place a copy in <tt>/usr/local/bin</tt>.
* '''6.''' Create the file /usr/local/bin/ldid2. Make it executable. Fill it with:
+
* '''6.''' Create the a Python script <tt>/usr/local/bin/ldid3.py</tt>. Make it executable. Fill it with:
<source lang="bash">
+
<source lang="python">
#!/bin/sh
+
#!/usr/bin/env python
  
hasGTA=`expr "$*" : '.* -gta .*'`;
+
from sys import argv
objpath=${!#}/`expr ${!#} : '.*/\([^/]\{1,\}\)\.app$'`;
+
from subprocess import check_call
 +
from os.path import basename, splitext, join
 +
from tempfile import NamedTemporaryFile
  
if [[ $hasGTA == 0 ]]; then
+
app = argv[-1]
/usr/local/bin/ldid -S $objpath;
+
obj_path = join(app, splitext(basename(app))[0])
else
+
 
TF=`mktemp -t x`;
+
if '-gta' not in argv:
echo "<!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>" > $TF;
+
    check_call(['/usr/local/bin/ldid', '-S', obj_path])
/usr/local/bin/ldid -S$TF $objpath;
+
else:
rm $TF;
+
    with NamedTemporaryFile() as f:
fi;
+
        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>
 +
        """)
 +
        check_call(['/usr/local/bin/ldid', '-S' + f.name, obj_path])
 
</source>
 
</source>
* '''7.''' Open <tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt> For Xcode 4.2 the path is: <tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>
+
* '''7.''' Open "<tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>" For Xcode 4.2 the path is: "<tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>"
* '''8.''' Replace the line saying <tt>CommandLine = "/usr/bin/codesign"</tt> with <tt>CommandLine = "/usr/local/bin/ldid2"</tt>. It should be around line 12.
+
* '''8.''' Replace the line saying <tt>CommandLine = "/usr/bin/codesign"</tt> with <tt>CommandLine = "/usr/local/bin/ldid3.py"</tt>. It should be around line 12.
 
* '''9.''' Save the file and restart Xcode.
 
* '''9.''' Save the file and restart Xcode.
  
 
If you upgrade the iPhone SDK, you need to perform steps 8 – 9 again.
 
If you upgrade the iPhone SDK, you need to perform steps 8 – 9 again.
 
'''NOTE''': ldid only supports thin binaries. Make sure you only build for one architecture in your build settings.
 
  
 
=== Allowing apps with invalid signatures to be installed ===
 
=== Allowing apps with invalid signatures to be installed ===
These steps allow you to install an unsigned app to the device. Embarrassedly, like all other MobileInstallation/installd patches, this allows pirated apps to be installed via iTunes as well.
+
These steps allow you to install an unsigned app to the device. This method only works for iOS 4.0 or above.
  
* '''10.''' Copy <tt>/usr/libexec/installd</tt> from your device to your Mac.
+
* '''10.''' Create a file <tt>/var/mobile/tdmtanf</tt> on the device, to enable Apple's "TDMTANF bypass" in <tt>installd</tt> (warning: doing so will also put you in a sandboxed GameCenter<ref>https://discussions.apple.com/thread/2745420?start=0&tstart=0</ref>).
* '''11.''' Run this:
 
install_name_tool -change /usr/lib/libmis.dylib /usr/lib/libmiss.dylib installd
 
ldid -S installd
 
* '''12.''' Create a file named <tt>libmiss.c</tt>, and enter these into the file:
 
<source lang="c">extern int MISValidateSignature() { return 0; }</source>
 
* '''13.''' Compile <tt>libmiss.c</tt> to <tt>libmiss.dylib</tt> with <tt>gcc</tt> targeting iPhone:
 
# NOTE: Must provide a valid path for -isysroot.
 
 
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2                  \
 
  -arch armv6                                                                    \
 
  -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk \
 
  -dynamiclib                                                                    \
 
  -install_name /usr/lib/libmiss.dylib                                            \
 
  -current_version 1                                                              \
 
  -compatibility_version 1                                                        \
 
  -Wl,-reexport-lmis                                                              \
 
  -flat_namespace                                                                \
 
  -o libmiss.dylib                                                                \
 
  libmiss.c
 
ldid -S libmiss.dylib
 
* '''14.''' Copy the new <tt>installd</tt> to the device's <tt>/usr/libexec</tt>, and the <tt>libmiss.dylib</tt> to the device's <tt>/usr/lib</tt>.
 
  
If you upgrade the firmware, you need to do step 14 again.
+
If you upgrade the firmware, you need to do step 10 again.
  
 
== References ==
 
== References ==
 
<references/>
 
<references/>
* The original article — http://networkpx.blogspot.com/2009/09/compiling-iphoneos-31-apps-with-xcode.html
 

Revision as of 09:22, 22 January 2012

Xcode is the IDE endorsed by Apple for iPhoneOS development. The latest version 4.2. It comes with the official iPhone SDK.

Developing without Provisioning Profile

To develop for the devices one should first obtain a provisioning profile by joining the iPhone Developer Program (which costs $99). However, some simple tricks can be used to make Xcode compile and debug on jailbroken devices without provisioning profiles.

These steps are only tested for Xcode 3.2.x/iPhone SDK 3.x and Xcode 4.2.x/iPhone SDK 5.x. If for some reason you are stuck with Xcode 3.1.x, try [1].

Compiling

Performing these steps allows you to use Xcode to compile any applications and deploy it yourself.

  • 1. Create a self-signed code-signing certificate with the name “iPhone Developer” on the “login” (default) keychain using Keychain Access[1].
  • 2. Open /Developer/Platforms/iPhoneOS.platform/Info.plist
  • 3. Replace all occurrences of XCiPhoneOSCodeSignContext by XCCodeSignContext. There are three of them (XCode Version 3.2.4+).
  • 4. Save the file and restart Xcode.

If you upgrade the iPhone SDK, you need to perform steps 2 – 4 again.

Replacing codesign with ldid

These steps are necessary for debugging, since the entitlement can no longer be inserted by performing steps 1 – 4. To actually debug your app, make sure you have add -gta to Other Code Signing Flags of your target.

  • 5. Make sure you have ldid on your Mac[2]. Place a copy in /usr/local/bin.
  • 6. Create the a Python script /usr/local/bin/ldid3.py. Make it executable. Fill it with:
#!/usr/bin/env python

from sys import argv
from subprocess import check_call
from os.path import basename, splitext, join
from tempfile import NamedTemporaryFile

app = argv[-1]
obj_path = join(app, splitext(basename(app))[0])

if '-gta' not in argv:
    check_call(['/usr/local/bin/ldid', '-S', obj_path])
else:
    with NamedTemporaryFile() 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>
        """)
        check_call(['/usr/local/bin/ldid', '-S' + f.name, obj_path])
  • 7. Open "/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec" For Xcode 4.2 the path is: "/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec"
  • 8. Replace the line saying CommandLine = "/usr/bin/codesign" with CommandLine = "/usr/local/bin/ldid3.py". It should be around line 12.
  • 9. Save the file and restart Xcode.

If you upgrade the iPhone SDK, you need to perform steps 8 – 9 again.

Allowing apps with invalid signatures to be installed

These steps allow you to install an unsigned app to the device. This method only works for iOS 4.0 or above.

  • 10. Create a file /var/mobile/tdmtanf on the device, to enable Apple's "TDMTANF bypass" in installd (warning: doing so will also put you in a sandboxed GameCenter[3]).

If you upgrade the firmware, you need to do step 10 again.

References