1

アプリケーションにゲームセンターを実装するサンドボックスモードになっています。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);
        }
    }];

iOS6およびiOS5と互換性のあるコードが必要なので、2つの実装があることがわかります。iOS 6の場合、完了ハンドラーはUIViewControllernullとエラーを返します。私は、本番環境でも同じことが起こるのではないかと心配しています。シミュレータでは、すべて正常に動作します。

PS-あなたはいくつかのc++コードを見つけるでしょう、それは私のゲームがcocos2dxで書かれているのでGameCenterのc++ラッパーを実装しているからです...

4

1 に答える 1

3

誰かがインターフェイスからキャンセルしてゲーム センターにサインインすると、GKErrorCanceled が返されます。3 回連続でキャンセルすると、ゲーム センターが無効になることが警告されます。

ゲームセンターを無効にすることを選択した場合、インターフェイスは表示されなくなり、代わりに GKErrorCanceled が表示されます。

Game Center を無効にすると、サインインする唯一の方法は、実際の G​​ame Center アプリにアクセスすることです。

ゲーム センターを使用するすべてのアプリまたはアプリの組み合わせで 3 回連続で発生する可能性があり、ゲーム センターを使用するすべてのアプリでゲーム センターが無効になります。ゲームセンターにサインインするたびに3回連続でリスタート。

これは、サンドボックスと非サンドボックスの両方に適用されます。

これは、ios 5 と ios 6 の両方に対応しています。

于 2012-12-13T23:22:52.467 に答える