簡體   English   中英

iOS GameCenter GKErrorCanceled

[英]iOS GameCenter GKErrorCanceled

我在沙盒模式下在我的應用程序中實現游戲中心。 當我登錄到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編寫...

當有人取消退出界面登錄游戲中心時,它會給你GKErrorCanceled。 他們連續第三次取消,它會警告他們將禁用游戲中心。

如果他們確實選擇禁用游戲中心,那么它將不再顯示界面,它只會給你GKErrorCanceled。

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

連續3次可以在使用游戲中心的任何應用程序或任何應用程序組合中,並且將禁用所有使用游戲中心的應用程序的游戲中心。 每次登錄游戲中心時,連續3次重新啟動。

這適用於沙箱和非沙箱。

這適用於ios 5和ios 6。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM