2012-12-11 64 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文档中找到这个,这让我完全困惑。 –