2012-09-26 60 views
1

我曾經使用此代碼,以登錄用戶帳號在遊戲中心:iOS中有問題的遊戲中心6

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) 
    { 
     if (error != nil) 
     { 
      NSLog(@"LOGIN"); 
     } else { 
      NSLog(@"CANT LOGIN"); 
     } 
    }]; 

此代碼工作正常的iOS 5.x的,但崩潰在iOS 6中,我將不勝感激,如果你幫助解決它。

感謝

+0

此方法在IOS 6過時;改爲設置'authenticateHandler'屬性。 (這可能不會修復你的崩潰,因爲你需要顯示更多的代碼。) – titaniumdecoy

+0

這是我在GameCenter中登錄的代碼!(up),你能給我一個示例代碼嗎? – Moonlight

回答

0

在這裏,你有Game Center Programming Guide

這就是你必須在iOS6的用戶進行身份驗證:

- (void) authenticateLocalPlayer 
{ 
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; 
    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){ 
     if (viewController != nil) 
     { 
      [self showAuthenticationDialogWhenReasonable: viewController 
     } 
     else if (localPlayer.isAuthenticated) 
     { 
      [self authenticatedPlayer: localPlayer]; 
     } 
     else 
     { 
      [self disableGameCenter]; 
     } 
    }]; 
} 

你也應該籤this question,因爲你的應用程序可能是由於自轉崩潰問題和遊戲中心,而不是認證機制本身

+0

非常感謝Lio,這段代碼一起工作在iOS 5和iOS 6上?我的遊戲在iOS 5上運行得非常好。我希望我的遊戲能夠在iOS 5和iOS 6上一起工作!請幫助我。我有不可抗力的工作。多謝。 – Moonlight

+0

看到這個錯誤:http://1.3.3.img98.net/out.php/i474324_screen-shot-2012-09-27-at18-pm.png – Moonlight

+1

這些錯誤是因爲我粘貼的代碼是示例代碼,你實際上必須實施這些方法。並回答你以前的方法,不,代碼將只能在iOS6中工作。我在iOS6中使用舊的iOS5代碼,它仍然可以正常工作。你應該追蹤崩潰並找出原因。我建議你看看我在答案中鏈接的那個問題。祝您好運 – Lio

3

你需要檢查我OS5或6 iOS6的改變認證功能

iOS6的

localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) 
    { 
     //Something 
    } 

的iOS5

[localPlayer authenticateWithCompletionHandler:^(NSError *error) 
    { 
     //Something 
    }]; 
1

這工作在IOS 6:

 GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; 
    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) { 
     if (viewController != nil) { 
      [self presentViewController:viewController animated:YES completion:nil]; 
     } else if (localPlayer.isAuthenticated) { 
      // do post-authentication work 
     } else { 
      // do unauthenticated work, such as error message, etc 
     } 
    };