2012-12-11 63 views
1

我在沙箱模式下在我的應用程序中實現遊戲中心。問題出在我登錄到gameCenter時,在某些設備上工作正常,在其他一些設備上,我得到一個GKErrorCanceled甚至沒有顯示的界面。iOS GameCenter GKErrorCanceled

此設備沒有任何用戶登錄gameCenter,因此與登錄非沙箱帳戶無關。我的代碼是:

 GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; 

    //First we try the new iOS6 authentification method for gamekit, if it's not implemented we will use the deprecated one 
    if ([localPlayer respondsToSelector:@selector(setAuthenticateHandler:)]) { 
     if (localPlayer.isAuthenticated) { 
      this->setState(connectionLoged); 
      this->getDelegate().socialConnectionDidSucceedLogin(*this); 
      return; 
     } 
     else if(!localPlayer.isAuthenticated && localPlayer.authenticateHandler){ 
      this->setState(connectionClosed); 
      this->getDelegate().socialConnectionDidFailToLogin(*this, std::string("The user already resign to login")); 
      return; 
     } 

     else{ 
      localPlayer.authenticateHandler = ^(UIViewController* viewController, NSError* error){ 
       if (localPlayer.isAuthenticated) 
       { 
        _name = [localPlayer.displayName UTF8String]; 
        _userId = [localPlayer.playerID UTF8String]; 

        [GKPlayer loadPlayersForIdentifiers:localPlayer.friends withCompletionHandler:^(NSArray *players, NSError *error) { 
         for (GKPlayer* player in players) { 
          if ([player isFriend]) { 
           NSDictionary* dict = 
           @{@"displayName" : player.displayName, 
           @"alias" : player.alias, 
           @"playerID" : player.playerID}; 

           AttrDictionary* playerInfo = [dict hydraAttrDictionary]; 
           SocialFriend* socialfriend = this->getNewFriendInstance(*playerInfo); 

           this->addFriend(socialfriend); 

           delete playerInfo; 
          } 
         } 

         this->getDelegate().socialConnectionDidSucceedLogin(*this); 
         this->setState(connectionLoged); 

        }]; 
       } 
       else if(viewController){ 
        UIViewController* rootViewController = (UIViewController*) [UIApplication sharedApplication].keyWindow.rootViewController ; 
        [rootViewController presentModalViewController:viewController animated:YES]; 
       } 
       else{ 
        if(error){ 
         this->getDelegate().socialConnectionDidFailToLogin(*this, std::string([error.description UTF8String])); 
        } 
        else{ 
         this->getDelegate().socialConnectionDidFailToLogin(*this, std::string("User cancelled login")); 
        } 
       } 

      }; 
     } 
    } 
//deprecated at IOs 6 authentification method 
else 
    [localPlayer authenticateWithCompletionHandler:^(NSError *error) { 
     if (localPlayer.isAuthenticated) 
     { 
      _name = [localPlayer.displayName UTF8String]; 
      _userId = [localPlayer.playerID UTF8String]; 

      [GKPlayer loadPlayersForIdentifiers:localPlayer.friends withCompletionHandler:^(NSArray *players, NSError *error) { 
       for (GKPlayer* player in players) { 
        if ([player isFriend]) { 
         NSDictionary* dict = 
         @{@"displayName" : player.displayName, 
         @"alias" : player.alias, 
         @"playerID" : player.playerID}; 

         AttrDictionary* playerInfo = [dict hydraAttrDictionary]; 
         SocialFriend* socialfriend = this->getNewFriendInstance(*playerInfo); 

         this->addFriend(socialfriend); 

         delete playerInfo; 
        } 
       } 

       this->getDelegate().socialConnectionDidSucceedLogin(*this); 
       this->setState(connectionLoged); 

      }]; 


     } 
     else{ 
      NSString* errorString = [error localizedDescription]; 

      this->getDelegate().socialConnectionDidFailToLogin(*this, std::string([errorString UTF8String])); 
      this->setState(connectionClosed); 
     } 
    }]; 

我需要的代碼與iOS 6和iOS 5兼容,所以你會看到我有兩個實現。對於iOS 6,完成處理程序返回UIViewController null和錯誤,如我所說。我擔心在製作中它會發生同樣的情況。在模擬器中一切正常。

PS-你會發現一些C++代碼,這是因爲我實現了GameCenter的一個C++封裝爲我的比賽是在cocos2dx寫...

+0

看看http://stackoverflow.com/questions/4317117/gamecenter-login-alert,有一個略微非正統的溶液。 –

回答

3

當有人取消了界面的登錄到遊戲中心,它會給你GKErrorCanceled。他們連續第三次取消,它會警告他們它會禁用遊戲中心。

如果他們選擇禁用遊戲中心,那麼它將不再顯示界面,而只會給你GKErrorCanceled。

一旦遊戲中心被禁用,登錄的唯一方法是進入實際的遊戲中心應用程序。

連續3次可以在任何應用程序或任何使用遊戲中心的應用程序組合中使用遊戲中心的所有應用程序都禁用遊戲中心。每次登錄遊戲中心時,連續3次重新開始。

這是用於沙箱和非沙箱。

這對於IOS 5和IOS 6.

+0

它確實是這樣的(GC在3個「取消」之後禁用了OS),但是有誰知道這是在哪裏陳述?!我無法在任何Apple文檔中找到這個,這讓我完全困惑。 –