7

Game Centerを使用しているゲームに取り組んでいますが、次の警告が表示されます。

...'authenticateWithCompletionHandler:'は非推奨になりました:iOS6.0で最初に非推奨になりました

OK、検索して、ローカルユーザーを認証するための新しいコードがあることがわかったので、置き換えました

古いコード:

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {
        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
    } else {
        NSLog(@"Already authenticated!");
    }
}

新しいもので:

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");

    if ([GKLocalPlayer localPlayer].authenticated == NO) {

        GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
        [localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
        //[localPlayer authenticateWithCompletionHandler:^(NSError *error) { OLD CODE!
            if(localPlayer.isAuthenticated) {
                //do some stuff
            }else {
                // not logged in   
            }
        })]; 
    } else {
        NSLog(@"Already authenticated!");   
    }   
}

そして、1つを除いてすべてが大丈夫です。ユーザーがログインしていない場合、ゲームセンターのログインフォームはありません。古いコードでは、ユーザーがログインしていない場合、GameCenterのログインフォームが表示されます。

私が入れなければならない余分なコードや何か他のものはありますか?

追加情報:-ランドスケープモード-展開ターゲット:6.0

4

1 に答える 1

10

はい、iOS6ではログインフォームを手動で表示する必要があります。これにより、画面を表示するタイミングをより細かく制御できます。これを試してみてください

localPlayer.authenticateHandler = ^(UIViewController *viewController,NSError *error) {
if (localPlayer.authenticated) { 
//already authenticated
} else if(viewController) {
[self presentViewController:viewController];//present the login form
} else {
//problem with authentication,probably bc the user doesn't use Game Center
} 
};
于 2013-01-21T08:14:45.323 に答える