7

这是关于GameCenter

由于“GKLocalPlayerListener协议继承了GKChallengeListener,GKInviteEventListenerGKTurnBasedEventListener.

为了处理多个事件”和“不要直接实现GKChallengeListener, GKInviteEventListener, 和GKTurnBasedEventListenerGKLocalPlayerListener改为实施。

您可以使用 " 侦听和处理多个事件GKLocalPlayerListener(这些来自苹果文档)。

人们会期望,在注册GKLocalPlayerListener之后,在经过身份验证之后,当适当的事件发生时,将调用GKLocalPlayer.localPlayer()中的所有方法。GKLocalPlayerListener

但是,除了调用“player(player: GKPlayer, receivedTurnEventForMatch match: GKTurnBasedMatch, didBecomeActive: Bool)”之外,其他所有方法,包括“player(player: GKPlayer, matchEnded match: GKTurnBasedMatch)”,在此类事件发生时都不会被调用。

我们需要注册其他听众还是我缺少什么?

4

4 回答 4

8

关于检测您已被邀请参加基于回合的比赛:没有发送任何事件,但是当您从服务器查询您的比赛列表时,您会突然出现一个新的比赛(并且您的状态将被邀请)。(不过,收件人确实会收到 UIAlert 提示他们已收到邀请)

关于各种 API 函数是否/何时触发,我花了很多很多时间试图破译这些各种功能何时触发。我已经针对函数或文档打开了多个错误。这是我目前的笔记;这就是我在帮助程序类中组织所有委托函数的方式,指示它们应用到哪个侦听器以及导致它们触发的原因的注释。

你可以看到有几个我从来没有破译过。对此列表的任何其他输入/说明将不胜感激。

#pragma mark - specific to real-time matches
//this is for real-time matches only (but the docs don't say that)
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite



#pragma mark - saved game listener (GKSavedGameListener)
//never fires. Theory: only fires if the SAME player tries to save the game from a different device while being the active player
-(void)player:(GKPlayer *)player didModifySavedGame:(GKSavedGame *)savedGame

//never fires. Theory: only fires if the SAME player tries to save the game from a different device while being the active player
-(void)player:(GKPlayer *)player hasConflictingSavedGames:(NSArray *)savedGames



#pragma mark - game launched via game center (GKLocalPlayerListener)
//DEPRECATED: This is fired when the user asks to play with a friend from the game center.app
-(void)player:(GKPlayer *)player didRequestMatchWithPlayers:(NSArray *)playerIDsToInvite

//This is fired when the user launches the game from Game Center and requests to play with a friend
-(void)player:(GKPlayer *)player didRequestMatchWithRecipients:(NSArray *)recipientPlayers

//Never seen this fire. Possibly fired when the user launches the game from Game Center. Unclear how this varies from didRequestMatchWithRecipients
-(void)player:(GKPlayer *)player didRequestMatchWithOtherPlayers:(NSArray *)playersToInvite



#pragma mark - Ending turn based matches (GKLocalPlayerListener)
//I've never seen this fire
-(void)player:(GKPlayer *)player matchEnded:(GKTurnBasedMatch *)match

//I've never seen this fire
-(void)player:(GKPlayer *)player wantsToQuitMatch:(nonnull GKTurnBasedMatch *)match



#pragma mark - challenges (GKLocalPlayerListener)
//untested, I don't use challenges
-(void)player:(GKPlayer *)player issuedChallengeWasCompleted:(GKChallenge *)challenge byFriend:(GKPlayer *)friendPlayer

//untested, I don't use challenges
-(void)player:(GKPlayer *)player didCompleteChallenge:(GKChallenge *)challenge issuedByFriend:(GKPlayer *)friendPlayer

//untested, I don't use challenges
-(void)player:(GKPlayer *)player didReceiveChallenge:(GKChallenge *)challenge

//untested, I don't use challenges
-(void)player:(GKPlayer *)player wantsToPlayChallenge:(GKChallenge *)challenge



#pragma mark - exchanges (GKLocalPlayerListener)
//seems to work as expected
-(void)player:(GKPlayer *)player receivedExchangeCancellation:(GKTurnBasedExchange *)exchange forMatch:(GKTurnBasedMatch *)match

//this fires for the Current Player AND the Exchange Initiator AFTER all replies/timeouts are complete.
-(void)player:(GKPlayer *)player receivedExchangeReplies:(NSArray *)replies forCompletedExchange:(GKTurnBasedExchange *)exchange forMatch:(GKTurnBasedMatch *)match

//seems to work as expected
-(void)player:(GKPlayer *)player receivedExchangeRequest:(GKTurnBasedExchange *)exchange forMatch:(GKTurnBasedMatch *)match



#pragma mark - event handler (GKLocalPlayerListener)
-(void)player:(GKPlayer *)player receivedTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive
/*
    Apple says this fires when:
    1. When it becomes the active player's turn, including the inviting player creating a new match (CHECK)
    2. When the time out is about to fire (FAIL. It fires AFTER the timeout expires, which may just be item #4 happening)
    3. Player accepts an invite from another player (FAIL. Never happens. Instead it fires when an INVITED player starts playing a session FROM this player.)
    4. Turn was passed to another player. (CHECK)
    5. player receives a reminder (CHECK, confirmed by μ4ρκ05)

    It Also fires when:
    6. A remote user quits (CHECK)
    7. A remote user declines (unconfirmed)
    8. An automatch player joins the game (CHECK)
    9. An invited player starts playing (CHECK)
    10. A remote user saves the game (CHECK)
*/

编辑:根据 μ4ρκ05 的反馈更新了“提醒”通知的状态。

于 2015-12-24T22:39:43.257 回答
1

好的,您对各种方法的列表和解释让我思考。首先。收到比赛时没有收到通知的问题对我来说是最紧迫的问题之一,因为如果您没有收到通知,则意味着您需要提取数据。那么,您何时再次加载匹配项?每 x 秒或每次带有游戏列表的视图控制器出现?两者都会发出不必要的网络调用,这会很烦人,而且由于游戏列表可能需要重新加载,没有任何实际更改,它可能看起来也不好。所以起初我在考虑使用交换,以便对手可以得到通知并重新加载游戏。然而,读了你的帖子,我想起了player receives a reminder (UNTESTED)那个叫做receivedTurnEventForMatch. 现在,我设法通过初始化新游戏、转弯、然后发送提醒来让对手收到新游戏的通知。

我已经更新了我的TurnBasedSkeleton项目。

于 2015-12-25T08:54:36.070 回答
1

我没有足够高的声誉来评论 Thunks 的答案,但我可以提交我自己的,所以这就是我将这些信息发布出去的方式。问题的最大部分是没有关于如何使用此代码的示例,并且缺少文档。因此,代码未触发并不能证明代码已损坏,只是我们不知道如何使用它。

但是根据 Thunk 所做的陈述,我能够得到 player:didModifySavedGame 和 player:hasConflictingSavedGames,他说他从未见过他们开火。

这些是 GKSavedGameListener 疯狂的方法。我对这个协议的问题是它没有一个委托来分配它,所以我可以在我的程序中选择任何类并使其符合这个协议,然后期望这些方法被触发,这似乎不太可能。所以我需要某种代表来说明哪个类符合要求。

我发现通过将 localPlayer.registerListener(self) 设置为 self 是符合标准的类,我可以让它们触发。

因此,请仔细检查任何未使用此 set 触发的方法,并让我们知道它是否工作得更好。

于 2016-03-31T07:30:25.247 回答
0

你没有错过任何东西。苹果选择了

删除 [这些] 功能

我向 Apple 提交了一个 bug 以进一步调查。至少可以说,他们的反应并不令人满意。

苹果错误报告

于 2016-04-30T04:31:21.783 回答