开发者

Detect when GameCenter UI is displayed

I'm trying to integrate my game with Game Center and encountered this problem:

When user is authenticated for a first time, Game Center shows its UI for setting up the profile.

My problem is that I can not detect when this windows is shown - I want to pause my game at that moment and not play any sounds.

viewWillDisapper, viewDidDisapper in UIViewController are not called, neither are any of AppDelegate methods are called at this t开发者_开发知识库ime.

I think I know how detect alert views (using changing key window notification), but that Account windows still is not detected there.

Is there any way to do this?


Building on executor21's answer here, I put this together which seems to do the trick in early testing. You can probably adapt it into something less fragile. It is built on the premise that the Game Center notification gets its own window, and it has exactly one subview of type GKGameEventView:

+(BOOL)isGameCenterNotificationUp
{
  NSArray *windows = [[UIApplication sharedApplication] windows];
  for(UIWindow *win in windows)
  {
    NSArray *winSubViews = [win subviews];
    if([winSubViews count] == 1)
    {
      Class gcNotificationClass = NSClassFromString(@"GKGameEventView");
      if(gcNotificationClass && ([[winSubViews objectAtIndex:0] isKindOfClass:gcNotificationClass]))
      {
        return YES;
      }
    }
  }
  return NO;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜