0

我有一个应用程序,正在尝试向游戏中心提交分数。这是我的代码:

- (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]);

} 但是,当我尝试这样做时,它不会提交给排行榜。我在调试器中没有收到任何错误,并且它曾经可以工作,直到我添加了多个排行榜。这里有什么问题?

4

2 回答 2

0

分数值必须是 int64_t。

而且我不明白您为什么使用 NSStrings 而不是直接分配值?

于 2012-08-18T23:24:01.467 回答
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];

}

于 2014-04-13T13:25:01.093 回答