次のデリゲート メソッドは、人が招待を受け入れると、gameKit によって呼び出されます。
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
NSLog(@"%@ accepted invite",player.playerID);
RIYGameNavigationController *root = (RIYGameNavigationController*)[[[UIApplication sharedApplication]delegate]window].rootViewController;
[root popToRootViewControllerAnimated:YES];
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc]initWithInvite:invite];
mmvc.matchmakerDelegate = root.viewControllers[0];
[[[[[UIApplication sharedApplication]delegate]window]rootViewController]presentViewController:mmvc animated:YES completion:nil];
}
これは、ユーザーがまだGKMatchmakerViewController
.
招待が届いたときにユーザーがすでに GKMatchmakerViewController を使用している場合、これは機能しません (例: ユーザーが既に一致を見つけようとしている場合)。この場合、招待が届いたときに次の警告が表示され、招待されたコントローラーは表示されません (表示されている matchmakercontroller が既に存在するため)。その結果、ユーザーは招待に応答できません。(何も起こりません)。
Warning: Attempt to present <GKMatchmakerViewController: 0x1458a250> on <RIYGameNavigationController: 0x1461f190> which is already presenting <GKMatchmakerViewController: 0x1465fcb0>
iOS6 では、次のようにしてこれを回避できます。
if([topLevelViewController modalViewController] != nil)
[topLevelViewController dismissModalViewControllerAnimated:NO];
を作成しGKMatchmakerViewController
ます。dismissModalViewControllerAnimated:
iOS6 で廃止されました。代わりに使用することをお勧めしますdissmissViewControllerAnimated:completion:
が、私にはうまくいきません。これは私が試したものです:
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
NSLog(@"%@ accepted invite",player.playerID);
RIYGameNavigationController *root = (RIYGameNavigationController*)[[[UIApplication sharedApplication]delegate]window].rootViewController;
[root popToRootViewControllerAnimated:YES];
if ([[root presentedViewController]class] == [GKMatchmakerViewController class]) {
[root dismissViewControllerAnimated:YES completion:nil];
}
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc]initWithInvite:invite];
mmvc.matchmakerDelegate = root.viewControllers[0];
[[[[[UIApplication sharedApplication]delegate]window]rootViewController]presentViewController:mmvc animated:YES completion:nil];
}
if ブロックに入りますが、既存の GKMatchmakerViewController は閉じられず、新しいものは表示されません。if ステートメントにブレーク ポイントを配置すると、ブレーク後に「続行」すると、ビュー コントローラーは閉じられますが、新しいビュー コントローラーはポップアップしません。
どうすればこれを機能させることができますか?