简体   繁体   English

不知道该怎么做才能添加Game Center排行榜

[英]don't know what I have to do to add Game Center leaderboard

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. 我试图添加一个Game Center排行榜,首先在iTunes Connect上进行设置,但是当我不得不用Xcode编写代码时,我不知道该怎么做。 I want to open the leaderboard with a shake gesture and for that I will use this code in the ViewController.m file: 我想用手势打开排行榜,为此,我将在ViewController.m文件中使用以下代码:

-(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? 而且,请问有人可以帮我晃动时出现排行榜吗?

  1. Enable GameCenter in the Project's capabilities tab 在项目的功能选项卡中启用GameCenter
  2. Create a GKGameCenterViewController instance 创建一个GKGameCenterViewController实例
  3. Set the appropriate viewState property 设置适当的viewState属性
  4. If necessary, set the gameCenterDelegate property 如有必要,设置gameCenterDelegate属性
  5. Present the VC: 展示VC:

     GKGameCenterViewController *vc = [GKGameCenterViewController new]; vc.viewState = GKGameCenterViewControllerStateLeaderboards; vc.gameCenterDelegate = self; [self presentViewController:vc animated:YES]; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM