Game Centerのハイスコアランキングを使う

正しくはハイスコアランキングじゃなくてLeaderboardだけど。ここの説明はあくまでも自分用のメモなので細かいことはGameKit Guideを参照のこと。

iTunesConnect側の設定

1. アプリをiTunesConnectに登録してないとGame Centerは使えないのでとりあえず登録する
2. アプリの設定画面を開いて「Manage Game Center」をクリック

3. 「Enable」をクリック

4. Leaderboardの「Edit」をクリック

5. アプリに合わせていろいろ設定

XCode側の設定

6. プロジェクトにGameKitフレームワークを追加


7. Info.plistのUIRequiredDeviceCapabilitiesにgamekitを追加

8. GameKitを使う

#import <GameKit/GameKit.h>

-(void)authenticateLocalPlayer {
  [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
    if (error) 
      { /* エラー処理 */ }
    else 
      { /* 認証済みユーザーを使ってハイスコアとか処理 */ }
  }];
}

-(void)reportScore:(int64_t)score forCategory:(NSString*)category {
  GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:cateogry] autorelease];
  scoreReporter.value = score;
  [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
    if (error) { /* エラー処理 */ }
  }];
}