Xcode Beta Woes

Sunday, January 31, 2010

So like most people who are on the ball, I downloaded the Xcode beta with the iPad SDK. Obviously this is what you should do right away if you're an iPhone developer because you should probably get at least vaguely familiar with the iPad and you might even want to port your software to it before the hardware is available.

That's all good, but it looks like there is at least one serious bug in the thing involving nib file loading. I had an application that kept crashing every time it tried to load a nib file. Normally this happens because some connection is pointing to a property that no longer exists or something, but in this case the thing was crashing even loading a brand new empty nib file, or a brand new nib file with one unchanged object.

I switched back to the release version of Xcode (3.2.1) and everything worked.

So it shouldn't come as a surprise, but there are still some serious issues with 3.2.2 that go beyond what I would expect even a beta to suffer from. I'd avoid using 3.2.2 for anything at all save for iPad tinkering.

Intercepting touch events before they reach controls

Thursday, January 14, 2010

Thought maybe I should mention this here since it seems to be necessary and very useful in certain situations:

http://stackoverflow.com/questions/2003201/observing-pinch-multi-touch-gestures-in-a-uitableview/2003781#2003781

Target Template for Building iPhone IPA Files

Saturday, January 9, 2010

I created a Xcode Target Template that makes it easy as pie to add an IPA target to your xcode project. Download it here!

If you're not familiar with IPA files, see this previous post on the subject. (The template file basically just encapsulates what's described in that post, but in a template file to make things easier.)

Instructions:
  1. Just add the 'IPA File Target.trgttmpl' template file to either of these directories:
    • "~/Library/Application Support/Developer/Shared/Xcode/Target Templates/Cocoa Touch"
    • "/Library/Application Support/Developer/Shared/Xcode/Target Templates/Cocoa Touch"
  2. In Xcode, right click on the Targets folder in your project or otherwise select the Add Target menu item from somewhere. Look under User Templates on the left, click Cocoa Touch, and there the template will be. Select it and add.
  3. Once you add the target you should edit it and add your Application target as a Direct Dependency. (That way the application will automatically get built first if you try to build the IPA target and the application isn't built yet.)
  4. To actually build the IPA file, change your Active Build Target from MyAppName to MyAppName.IPA in the Project->Set Active Target menu and build. (Of course you need to make sure you already have iPhone Device as the active SDK and your Release configuration set up with the proper code signing profile for an ad-hoc distribution since an IPA file with a debug build for the simulator isn't going to be too useful.)
I hope people find it useful. If so please leave a comment or send me a message so I know that I'm not talking to a wall or something....

Hiding an UIToolbar with ease-out animation

Friday, January 1, 2010

Here's a little code snippet that someone might find useful for people who want to allow users to hide a toolbar so the full screen can be used to view other content:
static BOOL toolbarHidden = NO;

// toolbar
[UIView beginAnimations:@"toolbar" context:nil];
if (toolbarHidden) {
toolbar.frame = CGRectOffset(toolbar.frame, 0, -toolbar.frame.size.height);
toolbar.alpha = 1;
toolbarHidden = NO;
} else {
toolbar.frame = CGRectOffset(toolbar.frame, 0, +toolbar.frame.size.height);
toolbar.alpha = 0;
toolbarHidden = YES;
}
[UIView commitAnimations];
Obviously the static variable only makes sense if you only have one toolbar. It would be more proper to put that in the class. You could also just use the alpha to determine if it's hidden if you're using that anyway, but I've been playing with different effects and have that commented out half the time.

If you also use setStatusBarHidden:animated: then it seems that the only effect you can get is the alpha fade in and out, so using that somehow on the status bar helps the animations match. You can't change the frame of the status bar.

In case you aren't aware, it's worth noting that setting alpha to 0 will not only visually hide a view but it will also no longer receive events which would appear to make it equivalent to using hidden = YES. Using toolbar.hidden doesn't seem to work with Core Animation.

There are more elaborate examples on this guy's blog.

Wax is Lua for Cocoa Touch

Tuesday, November 17, 2009

You should check out Wax! I haven't really used it yet but I've installed it, compiled the example, and looked at the code, and from what I've seen it looks pretty amazing in how it bridges between Lua and the Objective-C runtime. Both wax and Lua are incredibly small/fast. There's more tutorial type stuff at MobileOrchard.

Building IPA (iPhone Application) Files with Xcode

Monday, November 16, 2009

If you've sent an ad-hoc application bundle distribution to any Windows users then most likely one of them has been a little confused by it. This is because Mac application bundles receive no special treatment on windows and instead appear as a folder of other folders, and if you don't dig down to the right level in the hierarchy and drag the right folder into iTunes then iTunes doesn't install the application.

The way to avoid this is to build an IPA file which is the format that iTunes on both OS X and Windows store downloaded applications in. Basically the format is just a zip file with a specific directory structure and an ".ipa" extension instead of the normal ".zip" extension. Since it's just a single file whether you're using a Mac or Windows, it makes everything equally simple for everyone.

So it's not too hard to create an IPA file, but Xcode won't do it for you by default or using any built-in target templates. Luckily it's not that hard to get it to work.

A guy posted some instructions here on how to do this, but his build script was a little too hard-coded for me, so I improved on it a bit:
payload_dir="$CONFIGURATION_BUILD_DIR/Payload"
app_bundle_dir="$CONFIGURATION_BUILD_DIR/${PROJECT_NAME}.app"

/bin/rm -rf "$payload_dir"
/bin/mkdir "$payload_dir"
/bin/cp -R "$app_bundle_dir" "$payload_dir"
/bin/cp iTunesArtwork "$CONFIGURATION_BUILD_DIR/iTunesArtwork"
cd "$CONFIGURATION_BUILD_DIR"

/usr/bin/zip -r "${PROJECT_NAME}.ipa" Payload iTunesArtwork
rm -rf "$payload_dir" iTunesArtwork
These modifications allow you to just copy the script into any project without having to modify the script with the project name and such. Otherwise just follow his instructions.

You may also want to add the input and output files to support the dependency freshness checking stuff in the build system. This helps to ensure that a new IPA file doesn't get built from an old application bundle.