【问题标题】:Gamecenter Score Not Submitting Correct Score游戏中心分数未提交正确分数
【发布时间】:2014-07-15 02:35:11
【问题描述】:

当我测试我的游戏时,我的游戏分数在 3.49 秒内结束,但在 gamecenter 中,排行榜中显示的分数是 1:01:52.76。我认为问题是我得到一个黄色标志,表示从 NSString 分配给 int_64(又名 long 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

【问题讨论】:

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


    【解决方案1】:

    而不是当前行:

    scoreReporter.value = timeString;
    

    你应该使用:

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

    the following link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多