gpt4 book ai didi

ios - Gamecenter Score 未提交正确分数

转载 作者:行者123 更新时间:2023-11-28 22:02:42 24 4
gpt4 key购买 nike

当我测试我的游戏时,我的游戏得分在 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

最佳答案

您拥有的不是当前行:

scoreReporter.value = timeString;

你应该使用:

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

参见 the following link

关于ios - Gamecenter Score 未提交正确分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24726887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com