sunnyssrcp
sunnyssrcp

Reputation: 55

Game Center Integration for iPhone game?

Im a beginner for developing IOS applications mainly games. I have the game completed and have submitted it to the app store. In the mere future I want to submit an update which will include game center, primarily leader boards for scores (all time, monthly, weekly, and today). I'm having trouble understanding how to integrate the completed game with game-center. Another part that is unclear to me is what do I write in the code and how does gamekit framework know which number (score) to submit to game center. If anyone could provide detailed information I'd greatly appreciate it. Thanks!

Upvotes: 2

Views: 3310

Answers (3)

user3176949
user3176949

Reputation: 1

update score to game center use this routine.

- (void) reportScore: (int64_t) score   :(NSString*) YOUR_LeaderBoard_ID
{
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:YOUR_LeaderBoard_ID];
    scoreReporter.value = score;
    scoreReporter.context = 0;
    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil)
        {
            IsConnectFail = true;
        }else{
            IsConnectFail = false;   
        } 
    }]; 
}

Upvotes: 0

jcesarmobile
jcesarmobile

Reputation: 53351

here you have a sample project

http://developer.apple.com/library/ios/#samplecode/GKTapper/Introduction/Intro.html

To send the score you have this function, score is the score, category is the name of the leaderboard you configure on itunes connect.

- (void) reportScore: (int64_t) score forCategory: (NSString*) category {

GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:category] autorelease];
myScoreValue.value = score;

[myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
    if(error != nil){
        NSLog(@"Score Submission Failed");
    } else {
        NSLog(@"Score Submitted");
    }

}];
}

You have to use this function to send the score when your player is killed, you don't have to track if it has been the highest, but you can track if it's greater than 0;

This tutorial uses the sample project functions in his own project, take a look, it includes sending points and achivements

http://maniacdev.com/2011/05/tutorial-game-center-basics-leaderboards-and-achievements/

Upvotes: 6

Vimal Venugopalan
Vimal Venugopalan

Reputation: 4091

Game Center is available since iOS SDK 4.1

1) Open the Xcode Help.

2) On the top you should see a navigation bar, which should say "Documentation" section and move your mouse to where it says "iOS 5.1 Library"(in my case).

3) Now, move your mouse over "Networking & Internet" and click on it.

4) You now should have a list of available APIs.

After that just look around for the APIs you want, like Leaderboards, and achievements. According to your requirements you should look for things like GKLeaderboards, and anything else you are interested in. Those documentations should link to other documentations you would need. You can find the GKLeaderboards documentation on web

Edit: The game which you developed would be showing some score to the player after each instance of the Game. Post that score to the function - (void) reportScore: (int64_t) score forCategory: (NSString*) category eg. [self.gameCenterManager reportScore:yourscore forCategory: @"yourgamecategory"];

For the GameCenterManager.h and GameCenterManager.m from this link

Upvotes: 2

Related Questions