2014-12-29 2 views
0

행운이없이 Objective-C로 리더 보드를 만들려고합니다. 나는 여기와 다른 사이트에서 주변을 둘러 보았지만 작동하는 것을 찾을 수없는 것 같습니다. iTunes Connect에서 리더 보드를 만들었지 만 문제가있는 코드입니다. 일부 조건이 더 이상 사용되지 않는다는 경고가 나타납니다.리더 보드 (게임 센터)를 프로젝트에 구현하는 방법

- (IBAction)ShowLeaderboard:(id)sender { 

GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init]; 

if (leaderboardController != nil) { leaderboardController.leaderboardCategory = self; 

[self presentModalViewController: leaderboardController animated: YES]; } 

} 

- (IBAction)SubmitScoreToGameCenter:(id)sender { 

GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"LeaderboardName"]; 

scoreReporter.value = HighScoreNumber; 

[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) { if (error != nil){ NSLog(@"Submitting score failed"); } 

    else { NSLog(@"Submitting score succeeded"); } }]; 

} 

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController 

{ [self dismissModalViewControllerAnimated:YES]; 

} 

그리고이있는 viewDidLoad에서 : 당신이 실제로이를 검토 한 경우

{ 

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { if (error == nil) 

{ NSLog(@"Authentication Successful"); 

} 

    else { NSLog(@"Authentication Failed"); } }]; 
+0

https : //developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html –

+0

@TekayaMarouene별로 도움이되지 않습니다. 애플의 문서가 나를 혼란스럽게했다 ... 고마워. –

답변

2

,이 그래서에 자습서의 부하를 찾을 수

내가 사용하는 코드입니다 당신이 가지고 있다고 생각하지 않거나, xCode를 사용하는 법을 배웠던 적이 없습니다. 여기

내가 코드를 할 거라고 방법은 다음과 같습니다 리더 보드에 점수를 보내는의

-(void)submitScore //submit the score to game centre 
    { 
     GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:@"LeaderboardName"]; 
     int64_t GameCenterScore = Score; 
     score.value = GameCenterScore; 

     [GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) { 
      if (error != nil) { 
       NSLog(@"%@", [error localizedDescription]); 
      } 
     }]; 
    } 


-(void)authentication //log player into game centre 
{ 
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; 

    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){ 
     if (viewController != nil) { 
      [self presentViewController:viewController animated:YES completion:nil]; 
     } 
     else{ 
      if ([GKLocalPlayer localPlayer].authenticated) { 
       NSLog(@"authentication succcesful"); 
       GameCenterAvaliable = YES; 
       [[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) { 

        if (error != nil) { 
         NSLog(@"%@", [error localizedDescription]); 
        } 
        else{ 
         leaderboardIdentifier = leaderboardIdentifier; 
        } 
       }]; 
      } 

      else{ 
       NSLog(@"authentication unseuccseful"); 
       GameCenterAvaliable = NO; 
      } 
     } 
    }; 
} 

-(IBAction)ShowGameCenter:(id)sender //show game centre 
{ 
    GKLeaderboardViewController *LeaderboardController = [[GKLeaderboardViewController alloc] init]; 
    if (LeaderboardController != nil) { 
     LeaderboardController.leaderboardDelegate = self; 
     [self presentViewController:LeaderboardController animated:YES]; 
    } 
} 

//Animate gc out if finished with it 

-(void)leaderboardViewControllerDidFinish: (GKLeaderboardViewController *) viewController{ 
    [self dismissViewControllerAnimated:YES]; 
} 

을,하지만 난 당신이 실제로 리더를 설정하는 문제가 발생하는 것 같아? 예? iTunes Connect에서 리더 보드를 원하는 앱으로 이동하여 게임 센터로 이동하여 앱을 이동하십시오. 리더 보드 추가를 클릭하고 리더 보드 하나를 선택한 다음 정보를 입력하십시오. 리더 보드 ID는 코드에 입력 한 이름입니다. 위의 내 LeaderBoard 이름을 불렀습니다. 일단 게임을 끝내면 앱으로 돌아가서 게임 센터를 찾을 때까지 아래로 스크롤 한 다음 더하기 기호를 클릭하고 선택한 리더 보드를 추가합니다. 그러나 iTunes 연결에 응용 프로그램을 추가하는 방법을 모르는 경우 전체 기사를 심각하게 읽어야합니다 (예 : 여기에서 좋은 곳을 찾아보십시오) game centre.

+0

나는 이미 iTunes Connect에서 리더 보드를 만들었으므로 리더 보드 ID를 가지고 있습니다. 방금 코드를 올바르게 코딩하는 방법에 대한 자습서를 찾지 못했습니다. 최신이 아닙니다. 사용자가 Game Center에 로그인하게하려면 어떻게해야합니까? 위의 제공된 코드 (viewDidLoad)에서 볼 수 있듯이이 코드는 더 이상 사용되지 않습니다. 그리고 리더 보드를 여는 코드는 무엇입니까? –

+0

http://i.gyazo.com/eeee28bd52679876fa17b22195156a04.png –

+0

알아요.하지만 실행하고 완벽하게 작동합니다. 현재 앱 스토어에서 게임을 사용하고 있습니다. –

관련 문제