スコアをゲーム センターに送信するためのこのコードがありますが、ゲーム センター内でスコアを送信するたびに、スコアが 0 であると表示されます。GameKit フレームワークもインポートしました。
-(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";