0

ゲームをテストすると、ゲームのスコアは 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
4

1 に答える 1

2

あなたが持っている現在の行の代わりに:

scoreReporter.value = timeString;

以下を使用する必要があります。

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

次のリンクを参照してください

于 2014-07-14T18:30:15.200 に答える