簡體   English   中英

是否有一些有關實現游戲中心的簡單文檔?

[英]Is there some straightforward documentation on implementing the Game Center?

我正在嘗試將Game Center集成到我的ios7游戲(Xcode 5)中,但是Apple文檔中的內容以及我在網上看到的內容似乎效果不佳。

這是我正在使用的兩種主要方法,它們不會產生任何錯誤,但是我也沒有任何數據:

- (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");
    } 
 }];
}

所以我正在尋找一些簡單的示例代碼來成功完成此任務...謝謝rich

我認為您的代碼沒有錯。 播放器在運行時是否通過了身份驗證?您會遇到什么錯誤? 如果要查找示例GameKit代碼,Erica Sadun的iOS 6 Advanced Cookbook中有一些代碼,但是您應該無法理解如何閱讀該API。

答案是將iOS7中的分數提交給游戲中心

游戲中心幫助器/管理器/控件(對象).h

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

游戲中心助手/管理器/控件(對象).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) {

}];
}

視圖控制器

#import "gamecenterhelper/manager/control"

視圖控制器

[[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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM