Xcode: Difference between revisions

From iPhone Development Wiki
m ((updated "the latest stable version [of xcode] is 4.3" to 4.5.2))
m (Tested with Xcode 4.6.)
Line 1: Line 1:
Xcode is ''the'' IDE endorsed by Apple for iPhoneOS development. The latest stable version is 4.5.2. It comes with the official iPhone SDK.
Xcode is ''the'' IDE endorsed by Apple for iPhoneOS development. The latest stable version is 4.6. It comes with the official iOS 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/iPhone SDK 3.x, Xcode 4.3.x/iPhone SDK 5.x and Xcode 4.5.x/iPhone SDK 6.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 designed for the most recent version of Xcode and iOS SDK, but should also work for versions after Xcode 3.2/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].


=== Compiling ===
=== Compiling ===
Line 10: Line 10:


* '''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>.
* '''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>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Info.plist</tt> (4.2 or below: <tt>/Developer/Platforms/iPhoneOS.platform/Info.plist</tt>)
* '''2.''' Open <tt>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Info.plist</tt> (4.2 or below: <tt>/Developer/Platforms/iPhoneOS.platform/Info.plist</tt>). You may need root permission.
* '''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.


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


=== Replacing codesign with ldid ===
=== 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 <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 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>.
* '''5.''' Make sure you have ldid on your Mac<ref>If not, you can install from [http://pdb.finkproject.org/pdb/package.php/ldid Fink], compile it from git://git.saurik.com/ldid.git, or just download https://github.com/downloads/rpetrich/ldid/ldid.zip. Note that the version from [https://github.com/mxcl/homebrew/blob/master/Library/Formula/ldid.rb homebrew] was outdated!</ref>. Place a copy somewhere e.g. in <tt>/usr/local/bin</tt>.
* '''6.''' Create the a Python script <tt>/usr/local/bin/ldid3.py</tt>. Make it executable. Fill it with:
* '''6.''' Create the a Python script <tt>ldid3.py</tt> right next to the <tt>ldid</tt> program. Make it executable. Fill it with:
<source lang="python">
<source lang="python">
#!/usr/bin/env python
#!/usr/bin/env python
Line 26: Line 26:
from sys import argv
from sys import argv
from subprocess import check_call
from subprocess import check_call
from os.path import basename, splitext, join
from os.path import basename, dirname, splitext, join
from tempfile import NamedTemporaryFile
from tempfile import NamedTemporaryFile


app = argv[-1]
app = argv[-1]
ldid_path = join(dirname(__file__), 'ldid')
obj_path = join(app, splitext(basename(app))[0])
obj_path = join(app, splitext(basename(app))[0])


if '-gta' not in argv:
if '-gta' not in argv:
     check_call(['/usr/local/bin/ldid', '-S', obj_path])
     check_call([ldid_path, '-S', obj_path])
else:
else:
     with NamedTemporaryFile('w+b', 0) as f:
     with NamedTemporaryFile('w+b', 0) as f:
Line 45: Line 46:
</plist>
</plist>
         """)
         """)
         check_call(['/usr/local/bin/ldid', '-S' + f.name, obj_path])
         check_call([ldid_path, '-S' + f.name, obj_path])
</source>
</source>
* '''7.''' Open iPhoneCodeSign.xcspec.
* '''7.''' Open <tt>iPhoneCodeSign.xcspec</tt>. This file can be found in:
** For Xcode 4.5 the file is at: <tt><tt>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneCodeSign.xcspec</tt>
 
** For Xcode 4.3 the file is at: <tt>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>
{| class="wikitable"
** For Xcode 4.2 the file is at: <tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>
|-
** For older versions the file is at: <tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>
! Xcode version
* '''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. (For Xcode 4.5 replace line 6, <string>/usr/bin/codesign</string>, to <string>/usr/local/bin/ldid3.py</string>)
! Path
|-
| 4.5 - 4.6
| <tt>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneCodeSign.xcspec</tt>
|-
| 4.3
| <tt>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>
|-
| 4.2  
| <tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>
|-
| Before 4.2
| <tt>/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec</tt>
|}
 
* '''8.''' Change the entry in the file from calling <tt>codesign</tt> to <tt>ldid3.py</tt>. Specifically:
** Convert the file to a human editable format (esp. in Xcode 4.6 or above). You may skip this if the file is already in plain-text or XML format.<source lang="bash">
sudo plutil -convert xml1 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneCodeSign.xcspec
</source>
** Replace the entry (which should be near the beginning of the file)<source lang="xml"><key>CommandLine</key><string>/usr/bin/codesign</string></source>with<source lang="xml"><key>CommandLine</key><string>/usr/local/bin/ldid3.py</string></source>
 
* '''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 iOS SDK, you need to perform steps 8 – 9 again.


=== Allowing apps with invalid signatures to be installed ===
=== Allowing apps with invalid signatures to be installed ===

Revision as of 18:20, 10 February 2013

Xcode is the IDE endorsed by Apple for iPhoneOS development. The latest stable version is 4.6. It comes with the official iOS 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 designed for the most recent version of Xcode and iOS SDK, but should also work for versions after Xcode 3.2/iPhone SDK 3.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 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Info.plist (4.2 or below: /Developer/Platforms/iPhoneOS.platform/Info.plist). You may need root permission.
  • 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 iOS 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 somewhere e.g. in /usr/local/bin.
  • 6. Create the a Python script ldid3.py right next to the ldid program. Make it executable. Fill it with:
#!/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))[0])

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>
        """)
        check_call([ldid_path, '-S' + f.name, obj_path])
  • 7. Open iPhoneCodeSign.xcspec. This file can be found in:
Xcode version Path
4.5 - 4.6 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneCodeSign.xcspec
4.3 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec
4.2 /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec
Before 4.2 /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec
  • 8. Change the entry in the file from calling codesign to ldid3.py. Specifically:
    • Convert the file to a human editable format (esp. in Xcode 4.6 or above). You may skip this if the file is already in plain-text or XML format.
      sudo plutil -convert xml1 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneCodeSign.xcspec
      
    • Replace the entry (which should be near the beginning of the file)
      <key>CommandLine</key><string>/usr/bin/codesign</string>
      
      with
      <key>CommandLine</key><string>/usr/local/bin/ldid3.py</string>
      
  • 9. Save the file and restart Xcode.

If you upgrade the iOS 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