【问题标题】:iOS Game Center Sandbox: Leaderboards show "No score"iOS 游戏中心沙盒:排行榜显示“无分数”
【发布时间】:2012-02-03 17:21:34
【问题描述】:

所以我将分数发送到 GC 排行榜,我没有收到任何错误,并且分数也发送了,但我仍然看到排行榜中没有列出任何分数!排行榜本身在 Game Center 中列出,只是没有分数。

根据谷歌搜索和question on here,这可以通过尝试使用多个帐户记录分数来解决。我现在在模拟器(iOS5)和我的 iPhone 上都尝试了三个不同的帐户;提交分数时,它们都没有显示任何错误。

发送分数的代码在这里:

- (void)reportScore:(NSString *)identifier score:(int)rawScore {

    GKScore *score = [[[GKScore alloc] initWithCategory:identifier] autorelease];
    score.value = rawScore;
    [scoresToReport addObject:score];
    [self save]; // Save here even though we save again in didEnterBackground, just in case of crash...

    if (!gameCenterAvailable || !userAuthenticated) return;
    [self sendScore:score];
}

- (void)sendScore:(GKScore *)score {
    [score reportScoreWithCompletionHandler:^(NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^(void)
                       {
                           if (error == NULL) {
                               NSLog(@"Successfully sent score!");
                               [scoresToReport removeObject:score];                
                           } else {
                               NSLog(@"Score failed to send... will try again later.  Reason: %@", error.localizedDescription);                
                           }
                       });
    }];
}

【问题讨论】:

    标签: iphone objective-c game-center


    【解决方案1】:

    它突然开始工作(没有任何代码更改甚至重新编译)。我认为排行榜实际出现需要一段时间,对我来说大约需要 18 小时。

    在这段时间内提交的分数仍会记录,只是不会立即显示。

    【讨论】:

      【解决方案2】:

      我也从来没有将分数添加到沙盒中,但这是我实现的代码,它适用于当前应用商店中的版本:

      GKScore * score = [[[GKScore alloc] initWithCategory:@"com.example.appname.scoreboardname"] autorelease];
      score.value = [[NSUserDefaults standardUserDefaults] integerForKey:@"NEWSCORE"];
      [score reportScoreWithCompletionHandler:^(NSError *error) {
          dispatch_async(dispatch_get_main_queue(), ^(void) {
              if (error == NULL) {
                  NSLog(@"Score Sent");
              } else {
                  NSLog(@"Score Failed");
              }
          });
      }];
      

      只需确保您的 GKScore.value 的类型为 int64_t

      【讨论】:

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