1

I'm in sandbox mode implementing game center in my application. The problem comes when I log to gameCenter, in some devices works fine in some others I get a GKErrorCanceled without even get the interface shown.

This devices don't have any user logged in gameCenter so it's not related to have a non sandbox account logged. My code is:

       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);
        }
    }];

I need the code compatible with iOS 6 and iOS 5 so you will see I have the two implementations. For iOS 6 the completion handler returns with an UIViewController null and the error as I say. I'm afraid that in production it happends the same. In the simulator all works fine.

PS- You will find some c++ code, it's because I implement a c++ wrapper for GameCenter as my game is write in cocos2dx...

Jpellat
  • 907
  • 7
  • 29
  • have a look at http://stackoverflow.com/questions/4317117/gamecenter-login-alert, there is a somewhat unorthodox solution. – Nick Weaver Apr 10 '13 at 16:12

1 Answers1

3

When someone cancels out of the interface to sign in to game center, it will give you GKErrorCanceled. The third time in a row that they cancel, it will warn them that it will disable game center.

If they do choose to disable game center, then it won't show the interface anymore, and it will just give you GKErrorCanceled instead.

Once game center has been disabled, the only way to sign in is by going into the actual game center app.

The 3 times in a row could be in any app or any combination of apps that use game center, and game center will be disabled for all apps that use game center. The 3 times in a row restarts every time they sign in to game center.

This is for both sandbox and non-sandbox.

This is for both ios 5 and ios 6.

machoota
  • 289
  • 2
  • 5
  • It sure works like that (GC disabled OS-wide after 3 "cancel") but does anyone knows where this is stated?! I can't find that in any Apple Doc, which totally puzzled me. – StuFF mc Nov 25 '13 at 18:37