2012-04-23 34 views
0

我有這個代碼將我的分數提交給遊戲中心,但是每當我在遊戲中心內提交分數時,就會說我的分數是0.我不確定這是怎麼發生的?我也導入了GameKit框架。我查看了幾個教程,這些教程都來自Xcode的先前版本,但我不確定這是否有所作爲。GameCenter - 向遊戲中心提交分數的代碼不起作用 - Xcode - iOS

-(IBAction)submitScore{ 
if (highscore>0) { 

GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"MyLeaderBoardID"] autorelease]; 

scoreReporter.value = [[NSNumber numberWithInt:highscore] longLongValue]; 
NSLog(@"posted"); 
NSLog(@"%i",highscore); 

[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) { 
    if (error != nil) 
    { 
     NSLog(@"failed!!!"); 
     NSLog(@"%i",highscore); 
    } 
    else{ 
     NSLog(@"Succeded"); 

    } 
}];} 

我也有這個代碼簽署:

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){ 
if (error == nil) { 
    NSLog(@"authintication success"); 
} 
else{ 
NSLog(@"authintication failed"); 
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Game Center Disabled"message:@"For Game Center make sure you have an account and you have a proper device connection."delegate:self cancelButtonTitle:@"Ok"otherButtonTitles:nil]; 
    [alert show]; 
} 

}]。

self.currentLeaderBoard = @"MyLeaderBoardID"; 

回答

0

你確定你在iTunes Connect中設定的排行榜有「MyLeaderBoardID」爲排行榜ID?我看不出有什麼毛病代碼

0

我會盡量讓的int64_t並將其設置爲scorevalue ...

0

嗯,我是相當新的iOS中的編程和努力學習的分數報告,以遊戲中心。但是當我檢查你的代碼時,我猜測有兩種可能性:

1)「scoreReporter.value = [[NSNumber numberWithInt:highscore] longLongValue];」可能需要一個字符串值,而不是一個數值

2)的排行榜的ID可能不是「MyLeaderBoardID」

其他部分似乎是罰款,我的看法。

+0

這是如何從2012年5月提供的答案有什麼不同? – EWit 2014-09-16 14:51:32

0

也許這種方式...

GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"ID"];