Wednesday, 18 March 2009

iPhone OS 3.0 Beta


Well, I've taken the plunge and installed the iPhone OS 3.0 beta on my iPhone 3G.

... it's a one way trip just in case you didn't read bullet point 3 of the iPhone OS 3.0 beta pre-installation advisory notes.


I'm guessing this was a popular download as Apple's iPhone Dev Center site initially failed under the load.

Here's the cool stuff so far:
  • Cut Copy Paste (it works well)
  • Forwarding of text messages (which we had that around xmas)
  • Landscape for mail, notes and the new messages app (SMS++)
  • Global search (wish it had some filter icons eg apps only)
  • Synchronisation of notes (but only to Apple Mail and Mobile Me)
Most painful experience was having to reorganise my 150+ icons :-(


Thursday, 12 February 2009

Using Xcode Targets for Adhoc iTunes Artwork

By creating multiple Xcode targets you can adjust what files are included in each target.

eg iTunesArtwork for adhoc users or testers

As the iTunesArtwork file only works for adhoc builds you want to exclude it from debug and release builds.

To create an Adhoc target which includes your iTunesArtwork  file you need to:
  • Create a new Adhoc target
  • Add your iTunesArtwork file to your project
  • Change the target memberships for your iTunesArtwork
Step by Step:
  1. Duplicate the primary target (right click -> Duplicate)
  2. Rename the new target to Adhoc
  3. Add your iTunesArtwork file to your project as described here
  4. Change the target memberships for your iTunesArtwork file to Adhoc only using:
    Select Target -> right click -> Get Info -> Targets
    (make sure only Adhoc is selected)
Once you've made these changes you can explore the Target build phases. The iTunesArtwork file should only appear in Copy Bundle Resources for the Adhoc target.

It may be useful to have matching targets and configurations for each type of build eg
  • Debug
  • Adhoc
  • Release 
When changing the build type set both the active configuration and active target.

Other uses for multiple targets include:
  • Different icons for Debug / Adhoc / Release builds
  • Incrementing build numbers only for Adhoc / Release builds

Identifying the Current Xcode Configuration

The easiest way to identify the current configuration in code is by creating a preprocessor macro under your Xcode project build settings.

Step by step:
  1. Project menu -> Edit Project Settings -> Build tab
  2. Select All Configurations
  3. Scroll down to GCC 4.0 - Preprocessing
  4. Add the following to Preprocessor Macros Not Used in Precompiled Headers:

    CONFIGURATION_$(CONFIGURATION)
Assuming you have Debug, Adhoc and Release configurations, this will generate preprocessor macros for each configuration. ie
  • CONFIGURATION_Debug
  • CONFIGURATION_Adhoc
  • CONFIGURATION_Release
In your code you can now use something like:

#ifdef CONFIGURATION_Debug
NSLog(@"Debug message");
#endif

#if defined (CONFIGURATION_Debug) || defined (CONFIGURATION_Adhoc)
NSLog( @"Warning message");
#endif

Sunday, 7 December 2008

Updating Leopard's Pre-Installed Subversion

Here's the how to update Leopard's pre-installed copy of subversion.

Download and install the latest universal binary from CollabNet:
http://www.collab.net/downloads/community/includes/communitydownloads-getit-mac.html

The installer puts everything into /opt/subversion and creates symbolic links in /usr/local/bin but this doesn't disable the pre-installed copy in /usr/bin.

You need to get adventurous:
  1. Create symbolic links in /usr/bin/ and /usr/lib/ to the new subversion files in /opt/subversion/bin/ and /op/subversion/lib/
  2. Update your apache subversion configuration to use the new /opt/subversion/lib/svn-apache/mod_dav_svn.so
Note: do not update libapr to 1.0.2.12 as it will cause a problem with Apache.

Step by step using Terminal:

  1. Commit all your files and close all subversion clients eg Xcode
  2. If not logged in as an admin account switch user to an admin account:
    su admin
  3. Create links to the new subversion files:
    sudo ln -sf /opt/subversion/bin/svn* /usr/bin/
    sudo ln -sf /opt/subversion/lib/libsvn* /usr/lib/
  4. Edit your apache2 subversion configuration file: (your location may be different)
    sudo pico /etc/apache2/other/svn.conf
  5. Update LoadModule to:
    LoadModule dav_svn_module /opt/subversion/lib/svn-apache/mod_dav_svn.so

Saturday, 6 December 2008

Incrementing Your Build Number in Xcode

Here's a little shell script to increment a build number automatically with each build.

It assumes the following about your versions in info.plist:
  • Your product version is CFBundleShortVersionString in info.plist
    eg 1.0.0
  • Your build number is appended to your product version in CFBundleVersion
    eg 1.0.0.133
Step by step:

  1. Enter some default values in info.plist
    Bundle versions string, short: 0.1.0 (CFBundleShortVersionString)
    Bundle version: 0.1.0.1 (CFBundleVersion)
  2. Select your Target in Xcode
  3. Add a new run script build phase:
    Project -> New Build Phase -> New Run Script Build Phase
  4. Paste the script below into the script box
  5. Build your project
version=$(sed -n '
/^[[:blank:]]*CFBundleShortVersionString<\/key>$/ {
N
s/^[[:blank:]]*CFBundleShortVersionString<\/key>\n[[:blank:]]*\(.*\)<\/string>/\1/
p
}' info.plist)

build=$(sed -n '

/^[[:blank:]]*CFBundleVersion<\/key>$/ {
N
s/^[[:blank:]]*CFBundleVersion<\/key>\n[[:blank:]]*.*\.\(.*\)<\/string>/\1/
p
}' info.plist)

build=$(($build +1))


cp Info.plist 'Backup of Info.plist'


sed '

/^[[:blank:]]*CFBundleVersion<\/key>$/ {

N
s/\(\).*\(<\/string>\)/\1'"$version\.$build"'\2/
P
D
}' 'Backup of info.plist' > Info.plist

Each time you build using that target the build number will be incremented. A backup of your info.plist is made (just in case).

You could easily extend this script to commit files to your subversion repository.

The script uses multi-line sed and I'm no sed magician. If you're looking for a sed tutorial try here.