我认为子类化不是一个好主意。从一个干净的 UIViewController 开始,然后从那里构建 UI。然后实现所有必要的方法。
将自己设置为代表:
[GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate = self;
所以你得到委托事件,例如:
handleInviteFromGameCenter
handleTurnEventForMatch
handleMatchEnded
etc.
添加一个 UITableView,并从游戏中心加载所有比赛:
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error) {
// Add matches to table view
}];
不要忘记先验证播放器:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *loginVC, NSError *error)
{
};
以编程方式为比赛加注星标:
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
[GKTurnBasedMatch findMatchForRequest:request withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
{
}];
等查看完整 API 的文档。