Gamecenter得分未提交正确分数

时间:2014-07-13 20:45:32

标签: ios game-center game-center-leaderboard

当我测试我的游戏时,我的游戏分数在3.49秒的时间内结束,但在游戏中心,排行榜中显示的分数是1:01:52.76。我认为问题是我得到一个黄色标记,表示从NSString分配到int_64(又名长long)的不兼容整数到整数转换。以下是显示错误的代码部分。

    - (IBAction)buttonPressed:(id)sender {

    [self startTimer];

    count--;

    countLabel.text = [NSString stringWithFormat:@"Score\n%i", count];

    // 2

    if (count == 0) {

        [self.stopWatchTimer invalidate];

        timeLabel.hidden = YES;



        // Create date from the elapsed time

        NSDate *currentDate = [NSDate date];

        NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:self.startDate];

        NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];



        // Create a date formatter

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

        [dateFormatter setDateFormat:@"'Your time: 'ss.SSS"];

        [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];



        // Format the elapsed time and set it to the label

        NSString *timeString = [dateFormatter stringFromDate:timerDate];



        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Time is up!"

                                                        message: timeString

                                                       delegate:self

                                              cancelButtonTitle:@"Play Again"

                                              otherButtonTitles:@"Level Select",nil];



        [alert show];

        if (count == 0) {

            GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier:@"tap_novice"];



            scoreReporter.value = timeString;



            scoreReporter.context = 0;



            NSArray *scores = @[scoreReporter];



            [GKScore reportScores:@[scoreReporter] withCompletionHandler:^(NSError *error) {

                if (error == nil) {

                    NSLog(@"Score reported successfully!");

                } else {

                    NSLog(@"Unable to report score!");

                }

            }];

        }

    }    

}

@end

1 个答案:

答案 0 :(得分:2)

而不是当前行:

scoreReporter.value = timeString;

您应该使用:

int64_t timeAsInt = [timeString longLongValue];  
scoreReporter.value = timeAsInt;

请参阅the following link