0

我正在尝试将 Game Center 实现到我的 ios7 游戏(Xcode 5)中,但苹果文档中的材料和我在网上看到的东西似乎效果不佳。

这是我使用的两种主要方法,希望不会产生错误,但我也没有得到任何数据:

- (void) retrieveTopTenScores 
 {
  GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
  if (leaderboardRequest != nil)
   {
    leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
    leaderboardRequest.timeScope = GKLeaderboardTimeScopeToday;
    leaderboardRequest.identifier = kLeaderboardID;
    leaderboardRequest.range = NSMakeRange(1,10);
    [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
        if (error != nil)
        {
            // Handle the error.
        }
        if (scores != nil)
        {                
          // Process the score information. 
         } else {
           NSLog(@"scores retrieved successfully but no scores in the leaderboard"); 
        }
    }];
  }
}



-(void)submitMyScore
{
 //This is the same category id you set in your itunes connect GameCenter LeaderBoard
 GKScore *myScoreValue = [[GKScore alloc] initWithLeaderboardIdentifier:kLeaderboardID];
 myScoreValue.value = 5123123;

 [myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
    if(error != nil){
        NSLog(@"Score Submission Failed");
    } else {
        NSLog(@"Score Submitted");
    } 
 }];
}

所以我正在寻找一些简单的示例代码来成功地做到这一点......谢谢丰富

4

2 回答 2

0

答案是在iOS7中向游戏中心提交分数

Game Center Helper/Manager/Control (Object).h

 + (gamecenterhelper/manager/control *)sharedInstance;
 -(void)reportScore:(int64_t)score forLeaderboardID:(NSString*)identifier;

Game Center Helper/Manager/Control (Object).m

-(void)reportScore:(int64_t)score forLeaderboardID:(NSString*)identifier
{
GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier: identifier];
scoreReporter.value = score;
scoreReporter.context = 0;

NSArray *scores = @[scoreReporter];
[GKScore reportScores:scores withCompletionHandler:^(NSError *error) {

}];
}

视图控制器.h

#import "gamecenterhelper/manager/control"

视图控制器.m

[[gamecenterhelper/manager/control sharedInstance] reportScore:(int64_t) forLeaderboardID:(NSString*)];

//in place of int64_t place your integer you want uploaded, and instead on NNString* add your leaderboard identifier
于 2014-02-26T05:44:58.863 回答
0

我认为您的代码没有任何问题。运行时播放器是否经过身份验证?,你得到什么错误?如果您寻找示例 GameKit 代码,则有一些来自 Erica Sadun 的 iOS 6 Advanced Cookbook,但没有什么是您不应该能够弄清楚阅读 API 的。

于 2014-02-14T09:27:57.940 回答