4

私はCocos2d-iPhoneでゲームを構築していますが、iOS 6にアップデートしているときに、AppleがauthenticateHandler代わりにを使用してGameCenter認証の方法を変更したことに気付きましたauthenticateWithCompletionHandler

新しい認証方法を追加しましたが、プレーヤーがGame Centerにまだログインしていない場合、ゲームがクラッシュするようになりました。ユーザーがすでにログインしている場合は、認証に問題はありません。

これが私のコードです:

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
{
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
    {
        if (viewController != nil)
        {
            AppController *appDelegate = (AppController*)[UIApplication sharedApplication].delegate;

            [delegate.viewController presentViewController:viewController animated:YES completion:nil];
        }
        else if (localPlayer.isAuthenticated)
        {
            NSLog(@"Player authenticated");
        }
        else
        {
            NSLog(@"Player authentication failed");
        }
    };
}

まったく同じコードを使用して問題なく表示しようとしても、GameCenterviewControllerを表示しようとするとクラッシュしているようGKTurnBasedMatchmakerViewControllerです。

どんな助けでも大歓迎です。

編集:クラッシュ時にスローされる例外は次のとおりです。

Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

4

2 に答える 2

5

ここでは、クラッシュに関する有用な情報を見つけることができます。これが根本的な理由だと思います。 https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

アプリはデリゲートメソッドapplication:supportedIntefaceOrientationsForWindowを提供し、portraitが返されたマスク値の1つであることを確認する必要があります。

このクラッシュを修正するために、以下のコードを追加しました。

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
于 2012-09-28T11:17:47.917 に答える
0

同様の問題があり、viewDidLoad内からisAuthenticatedとauthenticateHandlerをテストしていましたが、現在のビューの読み込み中にゲームセンタービューを表示しようとするとクラッシュし続けました。このテストをviewDidAppearに移動しました

  • (void)viewDidAppear:(BOOL)animated {

今は正常に動作します...

また、iOS 6の場合、Game Centerは認証されていないユーザーに一度だけプロンプトを表示します。ユーザーがサインインを拒否すると、そのアプリのGame Centerが無効になり、ユーザーはGameCenterにアクセスしてログインする必要があります。

于 2012-09-27T10:30:27.920 に答える