在没有游戏中心视图控制器的情况下处理GKTurnBasedMatch的邀请 [英] Handle invitation to GKTurnBasedMatch without game center view controllers

查看:143
本文介绍了在没有游戏中心视图控制器的情况下处理GKTurnBasedMatch的邀请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的回合制文字游戏,我很难搞清楚邀请函是如何运作的。当用户A邀请用户B参加游戏时,我希望用户B能够在我的自定义匹配界面(即列出所有用户B的游戏的屏幕)中看到该游戏。如果用户B在被邀请参加游戏时点击通知,情况会很好,但如果用户B只是自己导航到应用程序,我仍然希望通过我自己的界面看到游戏。

I am working on a simple turn-based word game, and I'm having a difficult time figuring out how invitations are working. When user A invites user B to a game, I want user B to be able to see this game in my custom match interface (ie a screen where all of user B's games are listed). Things are fine if user B clicks on the notification when he is invited to a game, but I still want the game to be visible through my own interface if user B just navigates to the app on his own.

每当出现此匹配界面屏幕时,我使用 [GKTurnBasedMatch loadMatchesWithCompletionHandler:] 来获取所有本地玩家火柴。有了这个,我会假设用户B能够看到他被邀请的比赛,但是这个新的比赛没有出现。如果我通过 GKTurnBasedMatchmakerViewController 接受邀请,则用户按预期进入游戏,但更令人费解的是,如果我打开我的 GKTurnBasedMatchmakerViewController 然后在不接受邀请的情况下取消,新的匹配现在显示在我的自定义匹配界面中,但它缺少用户A发送的匹配数据。

Whenever this match interface screen appears, I am using [GKTurnBasedMatch loadMatchesWithCompletionHandler:] to get all of the local player's matches. With this, I would assume that user B would be able to see the match he has been invited to, but this new match doesn't show up. If I accept the invitation through the GKTurnBasedMatchmakerViewController, the user enters the game as expected, but what makes this even more puzzling is that if I open up my GKTurnBasedMatchmakerViewController and then cancel without accepting the invitation, a new match now shows up in my custom match interface, but it lacks the match data that was sent by user A.

总而言之,我真的只是想知道如何使用自定义界面正确显示和接受 GKTurnBasedMatch 邀请(而不是必须使用 GKTurnBasedMatchmakerViewController )。谢谢!

To sum up, I am really just wondering how to properly display and accept GKTurnBasedMatch invitations with a custom interface (rather than having to use GKTurnBasedMatchmakerViewController). Thanks!

推荐答案

这个问题似乎引起了一些人的兴趣,所以这里有一个粗略的近似我最终做的事情。

This question seems to be of interest to a couple people, so here's a rough approximation of what I ended up doing.

首先,新匹配根本没有出现的原因只是因为我没有调用 [GKTurnBasedMatch loadMatchesWithCompletionHandler:] 每次我希望视图像我一样刷新。所以我记得那里没有真正的问题。

First of all, the reason new matches weren't showing up at all was just that I wasn't calling [GKTurnBasedMatch loadMatchesWithCompletionHandler:] every time I wanted the view to refresh like I though I was. So no real issue there as I recall.

真正的问题是我收到并显示新的 GKTurnBasedMatch ,但没有数据(即对手的第一步动作是可用的。基本上, [GKTurnBasedMatch loadMatchesWithCompletionHandler:] 似乎无法保证为您提供最新的 GKTurnBasedMatch 对象可用。为了确保匹配是最新的,我还必须在返回的每个匹配上调用 [match loadMatchDataWithCompletionHandler:] [GKTurnBasedMatch loadMatchesWithCompletionHandler :] (其中匹配是其中一个GKTurnBasedMatches)。这将返回与该匹配关联的最新匹配数据作为 NSData 对象。然后我可以使用这个 NSData 来确保我的匹配表中的所有匹配都被刷新以反映游戏中心的最新变化。

The real issue was the case where I was receiving and displaying the new GKTurnBasedMatch, but none of the data (i.e. the opposing player's first move) was available. Essentially, [GKTurnBasedMatch loadMatchesWithCompletionHandler:] doesn't seem to guarantee providing you with the most up-to-date GKTurnBasedMatch objects available. To make sure the matches are up-to-date, I had to also call [match loadMatchDataWithCompletionHandler:], on each match returned by [GKTurnBasedMatch loadMatchesWithCompletionHandler:] (where match is one of those GKTurnBasedMatches). This returns the most current match data associated with that match as an NSData object. I was then able to use this NSData to make sure all the matches in my match table were refreshed to reflect the most recent changes in game center.

简而言之,在 GKTurnBasedMatch 对象上使用 loadMatchDataWithCompletionHandler 确保他们的数据是最新的。

In short, use loadMatchDataWithCompletionHandler on your GKTurnBasedMatch objects to make sure their data is up to date.

这篇关于在没有游戏中心视图控制器的情况下处理GKTurnBasedMatch的邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆