这是关于GameCenter

由于“GKLocalPlayerListener协议(protocol)继承了GKChallengeListenerGKInviteEventListenerGKTurnBasedEventListener的方法。

为了处理多个事件”和“请勿直接实现GKChallengeListenerGKInviteEventListenerGKTurnBasedEventListener;改为实现GKLocalPlayerListener

您可以使用“GKLocalPlayerListener”监听并处理多个事件(这些事件来自Apple文档)。

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

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

我们是否需要注册其他监听器,或者我缺少什么?

最佳答案

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

关于/何时启动各种API函数,我花了许多很多 小时来尝试破译这些各种函数何时启动。我已经针对功能或文档打开了多个错误。这是我目前的笔记;这就是我在帮助器类中组织所有委托(delegate)函数的方式,指示了它们适用于哪个监听器,并说明了导致它们触发的原因。

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

#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的反馈更新“提醒”通知的状态。

10-08 03:33