iOS Game Center提交float而不是int64_t

ric*_*ich 1 objective-c gamekit ios game-center gkscore

我试图向float我的游戏中心排行榜提交两位小数长度,但是唯一允许提交的格式是int64_t.我使用默认的Apple报告分数方法:

- (void)reportScore:(int64_t)score forCategory:(NSString *)category {
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];   
    scoreReporter.value = score;
    [scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) {
        [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
    }];
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用此方法为报表分数方法提供分数:

- (IBAction)increaseScore {
    self.currentScore = self.currentScore + 1;
    currentScoreLabel.text = [NSString stringWithFormat: @"%lld", self.currentScore];
    NSLog(@"%lld", self.currentScore);
}
Run Code Online (Sandbox Code Playgroud)

请帮忙,我一直在谷歌上搜索疯狂,无法找到答案.

Hei*_*koG 5

GameCenter只接受int64_t

显示为浮点数或小数值的值与显示为整数的值之间的唯一区别是小数点的位置,而实际上所有值都是int64_t.

如果您的内部表示是双倍的,并且您将游戏中心配置为在小数点后显示3位数,则必须通过乘以10 ^ 3并转换为整数将其转换为整数.

int64_t gameCenterScore = (int64_t)(doubleValue * 1000.0f)
Run Code Online (Sandbox Code Playgroud)