iOS排行榜游戏中心

问题描述:

我正在尝试将领导委员会与我的iOS游戏整合。iOS排行榜游戏中心

我看到GKScore类需要一个类别,但是,我只有一个排行榜。我没有在任何地方看到字段类别。我有本地化的领导委员会ID,领导委员会参考名称和领导委员会名称。我使用哪一个,如果有的话?

我提交了两个帐户的分数,但是,我从来没有在排行榜上看到任何分数。我正在使用模拟器。

+0

您正在使用模拟器。 iOS没有模拟器。 (我试图编辑你的问题,但编辑太小而无法接受,我没有发现任何值得更正的内容:P) – 2012-05-30 09:19:57

首先,不要使用模拟器。如果可以的话,请使用设备,因为许多功能(如向游戏中心提交分数)在模拟器上不起作用。您是否尝试记录尝试分数报告返回的错误?这会给你更多关于未来困难的细节。要回答您的问题,请使用排行榜ID作为类别。这里是你可以用它来提交分数类别的样本函数:

定义在头文件中的isGameCenterAvailable布尔和使用下面的代码设置它的值:

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"); 

使用这种方法提交的分数:

-(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]; 
    }]; 
} 

此代码由Steffen Itterheim撰写,他撰写了一本关于cocos2d游戏开发的书。这里是他和他的许多其他产品的链接:http://www.learn-cocos2d.com/

+0

感谢您的代码!我也发现这有帮助:http://www.cocos2d-iphone.org/forum/topic/20998 – 2012-04-29 15:10:02