我有一个应用程序,我正在尝试向游戏中心提交分数。这是我的代码:
- (IBAction) submitScore{
NSString *show = [[NSString alloc] initWithFormat:@"Note: Scores may take some time to update"];
self.note.text = show;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Submitted"
message:@"Your score has been submitted to the Gamecenter leaderboard"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
array = [NSMutableArray arrayWithContentsOfFile:Path];
NSString *s = [[NSNumber numberWithInteger:[array count]] stringValue];
NSString *denom = [NSString stringWithFormat: @"%d", 15];;
double resultInNum;
double sdouble = [s doubleValue];
double denomdouble = [denom doubleValue];
resultInNum = sdouble/denomdouble * 100;
if(resultInNum > 0)
{
self.currentLeaderBoard = kLeaderboardID;
[self.gameCenterManager reportScore: resultInNum forCategory: self.currentLeaderBoard];
Submit.enabled = NO;
}
array = [NSMutableArray arrayWithContentsOfFile:Path];
[array writeToFile:Path atomically:YES];
NSLog(@"Count: %i", [array count]);
} 但是,当我尝试这样做时,它不会提交给排行榜。没有我在调试器中收到的错误,它曾经工作,直到我添加了多个排行榜。什么错了?
答案 0 :(得分:0)
分数值必须是int64_t。
我不明白你为什么要使用NSStrings而不是直接赋值?
答案 1 :(得分:0)
只需确保您提供正确的代码即可提交分数。这是我非常喜欢的一种方式。即使你会收到警告,因为他们不希望你在iOS 7中使用它,它仍然有效。如果它不起作用,请告诉我。
(IBAction)submitscoretogamecenter{
GKLocalPlayer *localplayer = [GKLocalPlayer localPlayer];
[localplayer authenticateWithCompletionHandler:^(NSError *error) {
}];
//This is the same category id you set in your itunes connect GameCenter LeaderBoard
GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:@"insertCategory"] autorelease];
myScoreValue.value = scoreInt;
[myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
//insert what happens after it's posted
}];
[self checkAchievements];
}