2012-09-27 96 views
3

我在Cocos2d-iPhone中構建遊戲,當我更新到iOS 6時,我注意到Apple改變了Game Center身份驗證的方式,使用authenticateHandler而不是authenticateWithCompletionHandleriOS 6遊戲中心身份驗證崩潰

我添加了新的身份驗證方法,但如果一個球員是不是已經登錄到遊戲中心現在遊戲崩潰。有沒有問題,如果用戶已經登錄認證

這裏是我的代碼:

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) 
{ 
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; 
    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) 
    { 
     if (viewController != nil) 
     { 
      AppController *appDelegate = (AppController*)[UIApplication sharedApplication].delegate; 

      [delegate.viewController presentViewController:viewController animated:YES completion:nil]; 
     } 
     else if (localPlayer.isAuthenticated) 
     { 
      NSLog(@"Player authenticated"); 
     } 
     else 
     { 
      NSLog(@"Player authentication failed"); 
     } 
    }; 
} 

好像它試圖呈現遊戲中心的viewController時崩潰,即使我使用完全相同的代碼來呈現沒有問題的GKTurnBasedMatchmakerViewController

任何幫助將不勝感激。

編輯: 這裏是例外,越來越扔在崩潰:

Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

+1

崩潰的顯示詳細信息。日誌輸出,崩潰報告等 –

+0

我編輯我的帖子,包括未處理的異常。那是你需要的嗎? –

+0

我發現這一點:HTTP://stackoverflow.com/questions/12427979/gamecenter-authentication-in-landscape-only-app-throws-uiapplicationinvalidinter。現在不會崩潰,但它將在縱向而不是橫向上啓動GC模式視圖。 –

回答

5

在這裏你可以找到你的崩潰有用的信息,我認爲這是潛在的原因。 https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

應用程序應提供委託方法應用程序:supportedIntefaceOrientationsForWindow並確保肖像是返回的掩碼值之一。

我添加下面的代碼來解決這個崩潰。

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window 
{ 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 
+1

修復了我的崩潰,但現在GC身份驗證視圖出現在肖像中,而不是像我的應用程序的其餘部分一樣出現。你知道如何強迫它進入景觀? –

+1

它只有肖像。它正在崩潰,因爲你的應用只在風景中。上面的代碼意味着橫向或縱向(但不是顛倒),所以它以縱向顯示。這(無疑)會導致您的應用程序出現令人不快的旋轉現象。嘗試設置一個變量,當用戶通過身份驗證時返回其他內容。在Apple系統中輸入一個不支持格局的錯誤。 – bshirley

0

也有類似的問題,我在測試從內viewDidLoad中的isAuthenticated和authenticateHandler,一直試圖呈現遊戲中心視圖時崩潰而在中間加載當前視圖。我搬到這個測試到viewDidAppear

  • (無效)viewDidAppear:(BOOL)動畫{

它工作得很好,現在...

也適用於iOS 6,遊戲中心將只提示非認證用戶一次,如果他們拒絕簽入,這將禁用遊戲中心該應用,用戶屆時將有進入遊戲中心進行登錄。

+0

感謝您的建議,但它並沒有解決我遊戲中的崩潰問題。 –