Reputation: 4144
I am trying to integrate the leader board with my iOS Game.
I see that the GKScore class requires a category, however, I only have one leader board. I don't see the field category anywhere. I have a leader board ID, a leader board reference name, and a leader board name under localization. Which one do I use, if any?
I am submitting scores with two accounts, however, I never see any scores in the leader board. I am using the emulator.
Upvotes: 1
Views: 1066
Reputation: 281
First off, don't use the emulator. Use a device if you can because many features like submitting scores to game center don't work on the simulator. Have you tried logging the error returned by the attempted score reporting? This will give you more detail about future difficulties. To answer your question, you use the leader board ID as the category. Here is a sample function you could use to submit a score for a category:
Define the isGameCenterAvailable bool in the header file and set its value using the following code:
Class gameKitLocalPlayerClass = NSClassFromString(@"GKLocalPlayer");
bool isLocalPlayerAvailable = (gameKitLocalPlayerClass != nil);
// Test if device is running iOS 4.1 or higher
NSString* reqSysVer = @"4.1";
NSString* currSysVer = [[UIDevice currentDevice] systemVersion];
bool isOSVer41 = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);
isGameCenterAvailable = (isLocalPlayerAvailable && isOSVer41);
NSLog(@"GameCenter available = %@", isGameCenterAvailable ? @"YES" : @"NO");
Submit scores using this method:
-(void) submitScores:(int64_t)score category:(NSString*)category {
if (!isGameCenterAvailable){
return;
}
GKScore* gkScore = [[[GKScore alloc] initWithCategory:category] autorelease];
gkScore.value = score;
[gkScore reportScoreWithCompletionHandler:^(NSError* error) {
bool success = (error == nil);
if(!success){
NSLog(@"Error Reporting High Score: %@", [[error userInfo] description]);
}
[delegate onScoresSubmitted:success];
}];
}
This code was written by Steffen Itterheim, who wrote a great book on cocos2d game development. Here is a link to it and many other products by him: http://www.learn-cocos2d.com/
Upvotes: 3