Using OpenFeint with Sparrow

My Wiki Page

OpenFeint is a powerful social framework for iOS games. It makes it easy to handle achievements, leaderboards, and sharing. You can even synchronize it with Game Center. This tutorial only covers a basic OpenFeint integration and not any advanced features.


Tutorial Forum Post

This tutorial starts with the Sparrow scaffold. If you are not using the scaffold, your integration might be a little different.

1. Go to https://api.openfeint.com/dd/signup and sign up for an account.


If you already have an account, just create a new game from the developer dashboard.

2. Download the latest SDK from https://api.openfeint.com/dd/downloads.

I am using the OpenFeint iOS 2.12.5 package.

3. Find OpenFeint.framework in the SDK package and add it to your Sparrow project.

Also, add the correct configuration bundles for your project:

If your game is iPhone landscape only, use OFResources_iPhone_Landscape.bundle.
If your game is iPhone portrait only, use OFResources_iPhone_Portrait.bundle.
If your game is iPad only, use OFResources_iPad.bundle.
If your game is iPhone landscape and portrait, use OFResources_iPhone_Universal.bundle.
All others use OFResources_Universal.bundle.

4. Add the following frameworks to your project.

AddressBook
AddressBookUI
CFNetwork
CoreLocation
CoreText
GameKit
libsqlite3.0.dylib
MapKit
MobileCoreServices
Security
SystemConfiguration
At this point, you should be able to build and run your app with no OpenFeint related warnings or errors.

5. Add the following code in ApplicationDelegate.h and .m.

ApplicationDelegate.h

#import "OpenFeint/OpenFeint.h"
 
// Add OpenFeintDelegate after UIApplicationDelegate
@interface ApplicationDelegate : NSObject <UIApplicationDelegate, OpenFeintDelegate>

ApplicationDelegate.m

// At the end of applicationDidFinishLaunching
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:UIInterfaceOrientationPortrait], OpenFeintSettingDashboardOrientation,
@"OFSparrow", OpenFeintSettingShortDisplayName,
#ifdef DEBUG
[NSNumber numberWithInt:OFDevelopmentMode_DEVELOPMENT], OpenFeintSettingDevelopmentMode,
#else
[NSNumber numberWithInt:OFDevelopmentMode_RELEASE], OpenFeintSettingDevelopmentMode,
#endif
nil];
[OpenFeint initializeWithProductKey:@"qXprwYNXTJYdg1iT4lK9Eg" andSecret:@"xgVwRmTkhmOn5StvYiOruIDmL8dEEUyCniZgmLTn0o" andDisplayName:@"OpenFeint Sparrow" andSettings:settings andDelegates:[OFDelegatesContainer containerWithOpenFeintDelegate:self]];
 
// Add these methods also
- (void)dashboardWillAppear {
    [mSparrowView stop];
}
 
- (void)dashboardDidDisappear {
    [mSparrowView start];
}
 
- (void)userLoggedIn:(NSString *)userId {
    NSLog(@"User %@ logged into OpenFeint", userId);
}
 
// In the dealloc method
[OpenFeint shutdown];
6. Use these methods to open the OpenFeint dashboard.
// You may need to #import "OpenFeint/OpenFeint+Dashboard.h"
[OpenFeint launchDashboard];
[OpenFeint launchDashboardWithListLeaderboardsPage];
[OpenFeint launchDashboardWithHighscorePage:@"leaderboardID"];
[OpenFeint launchDashboardWithAchievementsPage];
[OpenFeint launchDashboardWithFindFriendsPage];
[OpenFeint launchDashboardWithWhosPlayingPage];
7. Use these methods to submit scores and achievements.
// You may need to #import "OpenFeint/OFHighScoreService.h" and "OpenFeint/OFAchievement.h"
[OFHighScoreService setHighScore:100 forLeaderboard:@"leaderboardID" onSuccessInvocation:nil onFailureInvocation:nil];
[[OFAchievement achievement:@"achievementID"] updateProgressionComplete:100.0f andShowNotification:YES];
8. Yay! You're done.

Here is the sample project from this tutorial.
Sample Project

  tutorials/using_openfeint_with_sparrow.txt · Last modified: 2013/03/05 10:19 (external edit)
 
Powered by DokuWiki