【问题标题】:Home Button doesn't terminate multiplayer match on Game Center / Gamekit主页按钮不会终止 Game Center / Gamekit 上的多人游戏
【发布时间】:2012-04-04 23:59:42
【问题描述】:

首先我必须说我是 iOS 开发新手。

我的问题是在使用 Game Center 进行多人游戏时。如果其他玩家(我的游戏是 2 人游戏)使用设备的主页按钮离开游戏,我现在不知道如何从 Game Center 获得通知。

我需要知道一个玩家何时关闭游戏,因为游戏在重新打开时总是从头开始,这意味着它会显示启动画面并直接进入主菜单。我尝试过重新匹配,但 Game Center 似乎正在创建新连接并寻找新玩家,同时玩家 2 继续与玩家 1“玩”而没有任何响应,因此他的匹配永远不会结束。

任何方法,didChangeState、matchmakerViewControllerWasCancelled 或 authenticationChanged,后者在通知下,似乎在按下主页按钮时会执行任何操作。

任何帮助将不胜感激

【问题讨论】:

    标签: notifications push-notification game-center gamekit multiplayer


    【解决方案1】:

    尝试订阅NSNoficationCenter 以了解您的应用何时进入后台:

    [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(userPressedHomeButton:) 
        name:UIApplicationDidEnterBackgroundNotification object:nil];
    

    在您的userPressedHomeButton: 函数中,您可以决定如何通知其他玩家或暂停游戏。但是,您必须迅速采取行动,因为 iOS 不允许您的应用在暂停后运行超过几秒钟。

    作为订阅 NSNotificationCenter 的替代方案,您可以在 AppDelegate 中进行实施:

    - (void)applicationWillResignActive:(NSNotification *)notification { }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多