所以我遇到了一些问题,而且我已经尝试解决它们大约两天了。
我设置了2个沙盒帐户,并在模拟器和我的设备上试过了应用程序。
游戏中心验证您的帐户/签名。
但是,一次只显示一个帐户分数,我不知道为什么。其次。而不是将得分显示为1分,2分等,这个数字确实是错误的。例如。
如果分数是三分,那就是#34; 392,868,960"甚至更大!
有谁知道为什么这可能是我可以解决的问题。此外,在xcode中,当我测试我的应用程序时,底部没有反馈。例如,NSLOG声明!
非常感谢任何帮助。使用的代码如下。非常感谢。
-(void)authentication //log player into game centre
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
}
else{
if ([GKLocalPlayer localPlayer].authenticated) {
NSLog(@"authentication successful");
GameCenterAvailable = YES;
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
leaderboardIdentifier = leaderboardIdentifier;
}
}];
}
else{
NSLog(@"authentication unsuccessful");
GameCenterAvailable = NO;
}
}
};
}
-(void)submitScore{
if (ScoreNumber > HighScoreNumber) {
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"Dodge_Leaderboard"] autorelease];
scoreReporter.value = [[NSNumber numberWithInt:ScoreNumber] longLongValue];
NSLog(@"posted");
NSLog(@"%i",ScoreNumber);
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
NSLog(@"failed!");
NSLog(@"%i",ScoreNumber);
}
else{
NSLog(@"Succeeded");
}
}];}}
-(IBAction)ShowGameCenter:(id)sender //show game center
{
GKLeaderboardViewController *LeaderboardController = [[GKLeaderboardViewController alloc] init];
if (LeaderboardController != nil) {
LeaderboardController.leaderboardDelegate = self;
[self presentViewController:LeaderboardController animated:YES completion:nil];
}
}
//Animate gc out if finished with it
-(void)leaderboardViewControllerDidFinish: (GKLeaderboardViewController *) viewController{
[self dismissViewControllerAnimated:YES completion:nil];
}
提交分数的新代码:
- (void)reportScore { if([GKLocalPlayer localPlayer] .isAuthenticated){ GKScore * scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier:@" Dodge_Leaderboard" forPlayer:[GKLocalPlayer localPlayer] .playerID]; scoreReporter.value = ScoreNumber; NSLog(@"分数记者值:%@",scoreReporter); [GKScore reportScores:@ [scoreReporter] withCompletionHandler:^(NSError * error){ if(错误!=无){ 的NSLog(@"错误&#34); //处理报告错误 }
}];
}}