iOS GameCenter GKErrorCanceled

时间:2012-12-11 17:29:44

标签: ios ios6 game-center

我正在沙盒模式下在我的应用程序中实现游戏中心。当我登录到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编写的......

1 个答案:

答案 0 :(得分:3)

当某人取消退出界面登录游戏中心时,它会给你GKErrorCanceled。他们连续第三次取消,它会警告他们将禁用游戏中心。

如果他们确实选择禁用游戏中心,那么它将不再显示界面,它只会给你GKErrorCanceled。

一旦游戏中心被禁用,登录的唯一方法是进入实际的游戏中心应用程序。

连续3次可以在使用游戏中心的任何应用程序或任何应用程序组合中,并且将禁用所有使用游戏中心的应用程序的游戏中心。每次登录游戏中心时,连续3次重启。

这适用于沙箱和非沙箱。

这适用于ios 5和ios 6.