私のゲームでは、プレイヤーはApplesGameCenterにログインする必要があります。彼らがゲームの新しいプレーヤーである場合、新しいユーザーアカウントの設定に使用されるデータの一部としてplayerIDを使用するため、最初にGameCenterにサインインする必要があります。
GameCenterクラスがあります。これを使用してプレーヤーにサインインするか、まだサインインしていない場合はサインインするように促します。メインコードは次のとおりです。
-(void) setup
{
gameCenterAuthenticationComplete = NO;
if (!isGameCenterAPIAvailable()) {
// Game Center is not available.
NSLog(@"Game Center is not available.");
} else {
NSLog(@"Game Center is available.");
__weak typeof(self) weakSelf = self; // removes retain cycle error
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; // localPlayer is the public GKLocalPlayer
__weak GKLocalPlayer *weakPlayer = localPlayer; // removes retain cycle error
weakPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
[weakSelf showAuthenticationDialogWhenReasonable:viewController];
}
else if (weakPlayer.isAuthenticated)
{
[weakSelf authenticatedPlayer:weakPlayer];
}
else
{
[weakSelf disableGameCenter];
}
};
}
}
-(void)showAuthenticationDialogWhenReasonable:(UIViewController *)controller
{
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:controller animated:YES completion:nil];
}
-(void)authenticatedPlayer:(GKLocalPlayer *)player
{
NSLog(@"%@,%@,%@",player.playerID,player.displayName, player.alias);
localPlayer = player;
gameCenterAuthenticationComplete = YES;
}
-(void)disableGameCenter
{
}
そして、それはうまくいきます。しかし、私には2つの問題があります。
1)プレーヤーが新しい場合は、新しいユーザーの登録を進める前に、GameCenterにサインインする必要があります。この新規登録は別のクラスにあります。では、他のクラスにGameCenterの変数gameCenterAuthenticationComplete = YESをリッスンさせるにはどうすればよいですか?デリゲートを使用できることを他の場所で読みましたが、それはオブジェクト間で機能しますか?通知はオブジェクト間でより適切でしょうか?
2)さらに重要なことに、プレイヤーがモーダルを閉じてGameCenterにサインインするとどうなりますか?モーダルが閉じられたときのコールバック/ブロックはどこにありますか?だから私は彼らに再度サインインするように促すことができますか、少なくとも画面にメッセージを表示することができますか?