2012-04-22 87 views
1

我有将代码提交给游戏中心的代码,但是每当我在游戏中心提交分数时就说我的分数是0.我不知道这是怎么发生的?我也导入了GameKit框架。Xcode-将分数提交给GameCenter

-(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

仅供参考用途,什么是你的分数?

您应该有两个不同的变量来读取旧分数和新分数。如果您的新分数大于您的旧分数,您希望将if语句设置为true。设置为大于零将使其每次用户得分大于0时都会不断变化。