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