Skip to content

Grunge Coding : How to implement OpenFeint in your iPod stuff…

August 18, 2010

Welcome to the first ‘Grunge Coding’ blog entry. I should probably explain that term, since it’s the first one…

‘Grunge Coding’ is not a term I invented, although it’s a term I have heard around a lot and it nicely describes the style. It’s basically ‘Getting stuff working in the quickest possible time, with the minimum of effort’, without any consideration for neatness or style. Shit coding basically, but it works. It’s useful for rapid prototyping, and for designers who don’t have a a hugely technical mind or who aren’t really interested in learning the thing inside out. Just the basics to get something working. Make it work first… then make it work fast.

The reason for posting is..

– It took me a while to collect all this information from various sources, now you don’t have to…

– If anything is grossly wrong, I hope people will point it out in the comments thread.

OpenFeint


OpenFeint is a lot like XBox Live, but for online / mobile platforms and iPods. It’s got loads of users.

It’s pretty much the dogs knackers until Apple’s Game Center stuff launches later this year.

This guide assumes that you kind of know what OpenFeint is (If not, go download some games and give it a go), and that you have an app ready to stick it into. Plus a basic knowledge of the platform.

Implementing it

1) Go to https://api.openfeint.com/ and register a developer account. You register a game title in the same process (You can add more later). You’ll need the ‘Product Key’ and ‘Product Secret’ later on, so note them down.

2) Download the Openfeint API from the same place, and put the ‘Openfeint’ folder into your project (Just drop it into your xCode ‘Groups and Files’ window somewhere, mine’s in ‘Resources’

3) You need to have the following frameworks added…

UIKit
Foundation
CoreGraphics
QuartzCore
Security
SystemConfiguration
libsqlite3.0
CFNetwork
CoreLocation
MapKit

You add new frameworks by right clicking on your frameworks folder in the Groups & Files panel, clicking Add->Existing Frameworks. Make sure all the ones above are added.

4) Add the prefix header file. Simply put the line;

#import “OpenFeintPrefix.pch”

In your prefix header file  (“MyAppName_Prefix.pch”)

I added it under the ‘#import <UIKit/UIKit.h>’ line.

Now, add;

#import “OpenFeint.h”

Somewhere on top of your App Delegate file (“MyAppDelegate.m”)

5) See if it still builds. If it still works, AWESOME! If it doesn’t, then I’m sorry. I have wasted your time. Return to step 1 or go look for someone who’s better at this than me.

6) OK, let’s see if it works now. Firstly, your didFinishLaunching function needs to be implemented like this…

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Then stick this stuff at the start of  your didFinishLaunching function.

NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight],
OpenFeintSettingDashboardOrientation, nil];

[OpenFeint      initializeWithProductKey:@”xxxxxxx”
andSecret:@”xxxxxxxxxxxxx”
andDisplayName:@”Your Game”
andSettings:settings
andDelegates:nil];

[OpenFeint respondToApplicationLaunchOptions:launchOptions];

The first line lets you change the orientation of the OpenFeint screen, the second initializes the app. Obviously, replace the secret / product keys / game name with your own which you got when you signed up.

Third line launches it.

7) Run your game again, you should see a screen like this right after loading…

Yayness!

Whatever players click here, this is the first and only time they’ll see this at initialization. If they decline, they’ll see the same screen again if they try and use your game’s OpenFeint features at a later point.

They’ll see notifications (Friend requests, messages) automatically the next time initialise.

If it all works, you can do some stuff! Here’s a description of some of that stuff…

Create a High Score table

Creating a high score table is really easy. Just log in to https://api.openfeint.com and click

Basic Features->Leaderboards->Create

Then enter the details. I’m not going to go through this… it’s a piece of piss. If you get in trouble, come get me.

Submitting a high score to the leaderboards

To submit a high score to one of your leaderboards, simply…

#import “OFHighScoreService.h”

Then, whenever you want to send a score to one of your leaderboards, probably at the end of a level,

[OFHighScoreService       setHighScore:dwScore
forLeaderboard:@”123456″
onSuccess:OFDelegate()
onFailure:OFDelegate()];

Obviously, replace the leaderboard ID and dwScore with your own. That’s it, you’ll even get a popup telling you if you’ve beaten the best score.

Launching the OpenFeint Dashboard

There will come a point when you want to give the player a chance to go look at their high scores ect… To do that, you simply call this line here…

#import “Openfeint.h”


[OpenFeint launchDashboard];

That’s all for now. I might update this page in the future, but honestly, the rest looks really easy. It’s the start that’s the hard bit.

Good luck,

Stu xxx

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: