0

I tried to add a Game Center leaderboard, first setting it on iTunes Connect but when I have to write the code in Xcode I don't know what I have to do. I want to open the leaderboard with a shake gesture and for that I will use this code in the ViewController.m file:

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if(event.subtype == UIEventSubtypeMotionShake) {
       // Code you want to run when the shake began
       }
}

Is that code right? And please can anyone help me what I have to do for appear the leaderboard when shaking?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217

1 Answers1

0
  1. Enable GameCenter in the Project's capabilities tab
  2. Create a GKGameCenterViewController instance
  3. Set the appropriate viewState property
  4. If necessary, set the gameCenterDelegate property
  5. Present the VC:

    GKGameCenterViewController *vc = [GKGameCenterViewController new];
    vc.viewState = GKGameCenterViewControllerStateLeaderboards;
    vc.gameCenterDelegate = self;
    [self presentViewController:vc animated:YES];
    
davidism
  • 121,510
  • 29
  • 395
  • 339
Aseider
  • 5,875
  • 1
  • 14
  • 25
  • I used this code but the message Game Center unavailable the player is not signed in appears and after that I can't interact with the screen(buttons, gestures, etc) :/ – Facundo Schiavoni Feb 07 '15 at 22:41
  • check your sandbox settings http://stackoverflow.com/questions/25945420/ios-8-game-center-error/25945487#25945487 – Valar Morghulis Feb 08 '15 at 08:26
  • You'll also have to authenticate the local player using `[[GKLocalPlayer localPlayer] setAuthenticateHandler:]` – Aseider Feb 10 '15 at 13:03