Eliminating class dependencies on your application delegate

Dec 4, 2009   //   by Rob Segal   //   Development  //  No Comments

Ever have the need to call a method inside your app delegate from an arbitrary place in your code?  We’ve had to deal with this issue in a few cases working on our new project.  We’re making use of a UIScrollView instance to give us that popular flick scroll movement that is so popular on the iPhone.  We’ve found that alot of people have been interested in doing the same thing and you can read our blog on that particular challenge here.  We have a UIScrollView instance sitting inside our app delegate and there are certain parts of our code where we need to move that UIScrollView among different layers in Cocos 2D.  To do that we need access to the scroll view instance itself.  That results in code like the following…

myAppDelegate *app = [[UIApplication sharedApplication] delegate];
UIScrollView *appOverlayScrollView  = (UIScrollView *)app.view;
[[app window] sendSubviewToBack:appOverlayScrollView];

This creates a messy dependency between an arbitrary class and the app delegate class.  Wouldn’t it be great if we could send a message to the app delegate and tell it to move the scroll view to the front or back maintaining encapsulation?  Turns out you can indeed do this.  The UIApplication class contains a method called sendAction which is normally used to send an action message identified by a selector to a specified target.  This method can easily be used to call selectors in any object so the above code can be converted to…

[[UIApplication sharedApplication]
sendAction:@selector(bringScrollViewToFront)
to:[[UIApplication sharedApplication] delegate]
from:self
forEvent:nil];

The only downside to this approach is that I haven’t found a way to supply arguments along with the selector so you need to be calling a method with no arguments.  If you know of a way around this issue please do let me know.

How to Display an Activity Indicator with UIActivityIndicatorView

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

We all wish that our apps could run without latency and pauses, but the reality is loading screens are needed from time to time. Today’s advent tip is how to display an activity indicator in your app like the one seen below. It’s great for soothing the savage, impatient user.

ActivityIndicator

It can actually be done with just a few lines of code. First, we create and position the UIActivityIndicatorView by doing the following. It needs to be added to a view, so be sure to replace “myView” with your own view.

UIActivityIndicatorView *activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
[myView addSubview: activityView];
activityView.center = CGPointMake(240,160);

So now the activity indicator is created and positioned but it isn’t visible yet. You can make it visible at any time by running the following one line:

[activityView startAnimating];

Finally, once you’ve finished loading the copious amounts of awesomesauce that fuel your app, you can make the activity indicator go away by running the following solitary line of code:

[activityView stopAnimating];

Addicus Reviewed by appSafari

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

Screen shot 2009-12-03 at 2.39.06 AMThe reviews are pouring in one after the other and we are loving what people have to say about Addicus. This latest one is by appSafari.com. Money quote:

The graphics are not only cute (everything bounces), but eye-catching. The music and sound effects are also cute, but if you’re the type who needs silence to do math, you might want to turn them off. Addicus makes math fun–which hasn’t happened since maybe second grade–and it’s bouncy, colorful, and challenging, so it’s well worth a download. It’ll come in handy the next time a dinner bill needs to be split.

Read the full review here

How to Show an Alert with UIAlertView

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

2

Showing an alert message to the user isn’t just a handy interface lick, it’s also an invaluable debugging tool. Thankfully, this functionality is built into the iPhone SDK.

To pop an alert with a title, message and OK button, we use the UIAlertView class like so:

UIAlertView *alert = [[UIAlertView alloc]
			initWithTitle: @"Announcement"
			message: @"It turns out that you are playing Addicus!"
			delegate: nil
			cancelButtonTitle:@"OK"
			otherButtonTitles:nil];
[alert show];
[alert release];

But what if you want to have more than one button on the alert and collect user input from it? Well that is pretty simple too. To do that, you first need to create a class that employs the UIAlertViewDelegate delegate like so:

@interface MyClass : NSObject <UIAlertViewDelegate>

Then, in your class, you need to override the alertView method in order to receive input like so:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
	if (buttonIndex == 0) {
		NSLog(@"user pressed OK");
	}
	else {
		NSLog(@"user pressed Cancel");
	}
}

Finally, we create the UIAlertView and pass in the delegate. Also note that we’ve labeled the Cancel button “Cancel” and added the “OK” button to the other button titles, which differs slightly from the above example.

UIAlertView *alert = [[UIAlertView alloc]
			initWithTitle: @"Announcement"
			message: @"It turns out that you are playing Addicus!"
			delegate: MY_DELEGATE
			cancelButtonTitle:@"Cancel"
			otherButtonTitles:@"OK",nil];
[alert show];
[alert release];

Addicus Gets Reviewed by AppSlappy

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

fert

Scott Johnson reviewed Addicus on this week’s episode of AppSlappy. Some highlights:

  • “weird little game”
  • “addicting”
  • “really digging it”
  • “4 out of 5 stars”
  • “highly recommend it”

Do listen to the whole show, because it is awesome, but if you want to skip right to the Addicus review then it starts during minute 23.

How to Open a URL in Safari

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

1Tis the season to broaden your iPhone dev chops! We have been developing on the iPhone platform for about 6 months now and it turns out that in that time, you tend to learn lots of little tips and tricks. Since we’re overcome by the spirit of giving around this time of year, we are going to be posting 24 of these bite-sized iPhone development tips, 1 every day between now and Christmas day. Consider it an advent calendar of iPhone dev tip goodies.

On With The First Tip!

Say you would like to open a URL in Safari. We used this on the “Get Set” button on the main menu of Addicus. Here is how to do it with just one line of code using the UIApplication class:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://getsetgames.com/"]];

The Next Game from Get Set

Nov 27, 2009   //   by Matt Coombe   //   Development  //  6 Comments

We thought it would be fun to show you a little preview of our next game which is currently in production. It’s still early days on this project so I won’t get into the details but you can expect a lot of action from this title!

Get Set Games - Next Game

Addicus Gets Reviewed by Macworld

Nov 27, 2009   //   by Derek van Vliet   //   In the Media  //  No Comments

Screen shot 2009-11-27 at 1.32.02 PM

Addicus got another glowing review today along with a solid 4/5 score. This time from granddaddy of Mac magazines, Macworld. Here’s a sample:

Overall, Addicus is simple to play, cool to look at, and yet challenging enough to keep you coming back again and again. Not many games manage to look and feel so childlike while still engaging adults who haven’t done addition drills in years. Addicus is a perfect way to pass time on a bus or in a waiting room, if you can keep your swearing under control.

Read the rest of the review here

Get Set Games is AppBoy’s Featured Developer

Nov 26, 2009   //   by Derek van Vliet   //   In the Media  //  No Comments

Screen shot 2009-11-26 at 2.36.02 AM

Mobile app-centric social network AppBoy interviewed Matt this week about our outfit. Topics covered include our past, present and future and of course some dish on everyone’s favorite new shroom-popping pastime: Addicus. Money quote:

These guys are true gamers and have been in the gaming space for a decade, something that obviously gave them a big head start when they began developing for the iPhone. Their game, Addicus, is a number-based puzzle that incorporates a simple and fun concept with great graphics and entertaining bonuses, which will get you hooked in no time.

Read the rest of the interview here

Addicus 1.1 and Addicus Free Version Submitted to the App Store

Nov 24, 2009   //   by Derek van Vliet   //   Announcements  //  No Comments

achievement_unlocked

Coming soon to an iPhone near you: an update to Addicus that features the following amazing new developments:

  • added over 70 unlockable achievements worth 1,000 Feint Score
  • option to publish to Twitter and Facebook
  • updated to OpenFeint 2.3.1
  • user interface improvements
  • minor bug fixes

Also, if you’ve been dying to try Addicus before you buy it, you will soon be able to. We have submitted a free version to the app store for approval.

These should both be available within the next couple of weeks.

Our Games

Latest Tweets