How to Hide (and Show) the Status Bar

Dec 11, 2009   //   by Derek van Vliet   //   Development  //  No Comments

On the iPhone’s 320×480 screen, pixel real estate is at a premium, especially for games. Often, the status bar represents 20 pixels of height that you as a developer just can’t afford to give away. Fortunately there are 2 simple ways to remove the status bar.


uistatusbarhidden2The first way is by adding a setting to your app’s info.plist file called UIStatusBarHidden. This is ideal for apps that should never display the status bar. Just follow these steps to change the setting:

1. Open your iPhone app’s info.plist file.

2. Command-click and select Add Row.

3. Select “Status bar is initially hidden” from the drop down that appears.

4. Check the checkbox that appears next to the new row.

You could also add this setting to your app’s info.plist file by opening it in a text editor and adding the following 2 XML tags inside the <dict> tag:


How to Do it With Code

If you need the status bar to appear and disappear at runtime, then you will need to use code to do so. You can hide the status bar with one line of code:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

And to show it again, simply call the above line and pass “NO” into setStatusBarHidden instead of “YES”. You can also fade the status bar in and out by passing “YES” into the “animated” part of the message.

String Comparison Using NSString

Dec 10, 2009   //   by Derek van Vliet   //   Development  //  3 Comments


One of the most common things a programmer needs to learn how to do when faced with a new API is how to compare one string to another to see if the two are the same or how they differ.

Because of this, many APIs have created some handy string comparison features, and the NSString class in objective-c is no exception. What follows are some invaluable tools for string comparison in objective-c.

The Is-Equal Method

The NSString class responds to a message and returns whether or not the NSString you pass in is equal or not:

NSString * str = @"oranges";
BOOL res = [str isEqualToString:@"apples"];

The Compare Method

The NSString class also has a method called compare, which gives you a bit more info in the return results. It can actually tell you the difference between the two strings; whether or not the string you passed in is:

  • the same,
  • in ascending sort order to the string you call the message on or
  • in descending sort order to the string you call the message on
NSString * str = @"oranges";
NSComparisonResult res = [str compare:@"apples"];
switch (res) {
	case NSOrderedAscending:
		// going up
	case NSOrderedSame:
		// even steven
	case NSOrderedDescending:
		// down i go

Insensitivity to Case

Finally, the NSString class also features a method for comparing strings without case sensitivity. This is useful for comparing strings with unpredictable case, such as user input. Like the compare method, it returns an NSComparisonResult enumerated value which allows you to see the equality or sort-order of the two strings.

NSString * str = @"APPLES";
NSComparisonResult res = [str caseInsensitiveCompare:@"apples"];
switch (res) {
	case NSOrderedAscending:
		// onward and upward
	case NSOrderedSame:
		// same old
	case NSOrderedDescending:
		// downfall

How to Set Your App’s Splash Screen

Dec 9, 2009   //   by Derek van Vliet   //   Development  //  2 Comments

All iPhone apps have a splash screen, or what Apple refers to as a “launch image”. It is the screen that is displayed immediately after you press your app’s icon on the home screen, while the app icons are sweeping away and your app is zooming into view.

Some apps opt not to display a splash screen and go for a black screen, which is the default behaviour when you create an app. Others display a wireframe of the app’s interface in order to look like it is loading faster. See Apple’s native apps such as Clock and Camera for good examples of this. The most common use of the splash screen (especially in games) is to present a company or game logo, as we do in Addicus:


How to Do It

Apple has made it so easy to set your splash screen that you don’t even need a single line of code to do it. Why, you don’t even need to change a setting. Here’s how to set your splash screen it in just 2 steps:

1. Add a file to your project’s Resource folder called Default.png.

2. There is no step 2. Take this time to reflect on how good life is.

And that’s it. Run your app and your splash screen will zoom into glorious view.

Heads Up

A couple of things to watch out for when working with splash screens:

Whatever image you give it will be scaled to fill the 320×480 resolution of the iPhone, so ideally you would use a 320×480-sized image.

If your iPhone app is running in landscape mode, you need to rotate the splash screen you use. For example, our splash screen is rotated 90 degrees to the right in the above image.

iTunes Connect Unavailable to Developers Dec 23 – Dec 28, 2009

Dec 8, 2009   //   by Derek van Vliet   //   PSA  //  No Comments

news_calendarAllow us to take a break from our adventures in iPhone development to give you a brief service announcement.

Apple just announced that iTunes Connect, the site that developers use to submit and manage their iPhone apps, will be unavailable from December 23 – December 28, 2009. Quote:

iTunes Connect, the tool you use to manage your applications and access your reports, will be unavailable from December 23 through December 28, 2009.

Access to iTunes Connect will resume December 29, 2009.

This means a couple of things:

1. Developers will be flying blind for 6 days. They will not be able to access their sales data, crash logs or financial reports until Dec. 29.

2. This also means no new apps or updates to apps can be submitted to Apple during this time. Developers may have to adjust their schedules accordingly.

3. Users who were hoping that an app will go on sale for Christmas day are most likely out of luck since developers will not be able to change their prices during that time. Unless developers are prepared to hold a 6 day sale, don’t expect many deals on apps after you open your iPhone on Christmas morning.

We now return to your regularly scheduled iPhone dev blog.

How to Get the Platform Name

Dec 8, 2009   //   by Derek van Vliet   //   Development  //  1 Comment

With each iPhone OS-powered device that Apple has added to its lineup, along with it has come new capabilities and new APIs. Because of this, it is often necessary for an app to figure out what platform it is running on before deciding to enable device-specific functionality, such as functionality that would use the compass on the iPhone 3GS, vibration on iPhones or GPS on iPhones.

Here is a function that serves just that purpose by returning the internal name of the platform:

#include <sys/types.h>
#include <sys/sysctl.h>
-(NSString*)getPlatformName {
	size_t size;  
	sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
	char *machine = (char*)malloc(size);  
	sysctlbyname("hw.machine", machine, &size, NULL, 0);  
	NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
	return platform;

Possible Values

The possible values that the above function will return when developing for the iPhone OS are listed below along with the product they represent.

Return Value Product
i386 iPhone Simulator
x86_64 iPhone Simulator
iPhone1,1 iPhone 1G
iPhone1,2 iPhone 3G
iPhone2,1 iPhone 3GS
iPhone3,1 iPhone ?
iPod1,1 iPod Touch 1G
iPod2,1 iPod Touch 2G

Example Usage

The following is an example of an if statement that takes advantage of the results of the above function.

NSString * platform = [self getPlatformName];
if ([platform isEqualToString:@"i386"]) {
	// do simulator-specific stuff, perhaps enable a more verbose level of logging?
else if ([platform isEqualToString:@"iPod2,1"]) {		
	// do iPod-specific stuff, perhaps disable UI that refers to GPS, vibration, etc.
else if ([platform isEqualToString:@"iPhone2,1"]) {
	// do iPhone 3GS-specific stuff, perhaps compass related?

Addicus Reviewed by AppShouter

Dec 8, 2009   //   by Derek van Vliet   //   In the Media  //  No Comments

Screen shot 2009-12-08 at 9.18.21 AM

AppShouter chimed in with the latest glowing review of Addicus today. Money quotes:

  • “a great game for both kids and adults.”
  • “The graphics are great and very cartoonish.”
  • “be careful because it is very addicting”

Read the full review here

How to Get the Current Time with NSDate

Dec 7, 2009   //   by Derek van Vliet   //   Development  //  No Comments

In iPhone app development, timing is everything. Being able to take a pulse on the current time is crucial to many apps, especially games. Fortunately, this can be done with as much ease as a developer would expect using the NSDate class in the iPhone SDK. Today’s iPhone development advent tip is another one-line wonder:

NSTimeInterval time = [[NSDate date] timeIntervalSince1970];

The timeIntervalSince1970 method returns the number of seconds since epoch. The return value type, NSTimeInterval, is a typedef of double, so you will have the necessary accuracy to get the current milliseconds from the first 3 digits after the decimal if need be.

How to Open the Mail App With a Pre-Composed HTML Email

Dec 6, 2009   //   by Derek van Vliet   //   Development  //  3 Comments

photo 2-1Have you ever wanted to open the Mail app with a pre-composed email? Then today’s iPhone development advent tip is the one for you! This has many uses, but a common one is a tell-a-friend feature in apps. If you attach the code from this tip to a button, you can give your users a way to promote your app to their friends via the iPhone’s built in Mail app.

A Handy Function

The sendEmailTo function, seen below, can be included in any class in your app. This function gives you a simple interface to send emails. It allows you to define “to” addresses, “cc” addresses, “bcc” addresses, a subject and a body. The body supports HTML tags.

- (void)sendEmailTo:(NSString*)to withCC:(NSString*)cc withBCC:(NSString*)bcc withSubject:(NSString*)subject withBody:(NSString*)body {
	NSString * url = [NSString stringWithFormat:@"mailto:?to=%@&cc=%@&bcc=%@&subject=%@&body=%@",
					  [to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
					  [cc stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
					  [bcc stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
					  [subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
					  [body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

NOTE: Running this function in the iPhone Simulator will have no effect because the simulator does not include the iPhone’s Mail app. To see the effects of this function, it must be run on a device.

Example Usage

Once you have that message defined in one of your classes, you can open the Mail app with a pre-composed email with just one message call. The following example opens an email and specifies a to, cc and bcc address. It populates the subject with “Addicus” and populates the body with a short message about Addicus that includes a link and an image (which is also a link). As you can see, this is done with good old HTML tags. This results in the email in the above screenshot.

[self sendEmailTo:@""
         withBody:@"<p>Check out this game, <a href=''>Addicus</a>, for the iPhone and iPod Touch. It's super-addictive!</p><p><a href=''><img src=''/></a></p>"];

If you would like to have the user specify the to, cc and bcc addresses themselves, as you would in the case of a tell-a-friend button, then you would call the following message:

[self sendEmailTo:@""
         withBody:@"<p>Check out this game, <a href=''>Addicus</a>, for the iPhone and iPod Touch. It's super-addictive!</p><p><a href=''><img src=''/></a></p>"];

How to Load a UIImage From a URL

Dec 5, 2009   //   by Derek van Vliet   //   Development  //  1 Comment

Early on in development of Addicus, we discovered how easy it was to load images from the web. This was a huge boon to us since it meant our artists could modify assets on our server and they would update live in the test builds, without having to make a new build.

This all hinged on the ability to load a UIImage from a URL. And as it happens, this can be accomplished in as little as one line of code:

UIImage * img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@""]]];

This eventually led to us writing a resource manager singleton class that handles all of our resource loading and can be toggled between local and web mode.

Addicus in the Spotlight on OpenFeint’s Shiny New Site

Dec 5, 2009   //   by Derek van Vliet   //   In the Media  //  No Comments

Screen shot 2009-12-04 at 11.50.29 PM

iPhone social game network OpenFeint launched version 0.1 of their new website today. The new site’s slick design is made even more beautiful by the loveable little shrooms of Addicus. For you see, Addicus is one of the games that OpenFeint has selected to feature in their spotlight.

We have so many good things to say about OpenFeint that I wouldn’t know where to begin. From the easy integration to the feature-filled product to the stellar level of support, they have all the bases covered. You can expect many more OpenFeint-enabled games from Get Set Games.

Our Games

Latest Tweets