Gamecenter ios 9 GameCenter GKLocalPlayerListener方法未调用

时间:2015-12-24 11:27:34

标签: ios swift game-center gkturnbasedmatch

这大约是GameCenter

由于" GKLocalPlayerListener协议继承了GKChallengeListenerGKInviteEventListenerGKTurnBasedEventListener中的方法。

为了处理多个事件"和"不直接实施GKChallengeListenerGKInviteEventListenerGKTurnBasedEventListener;实现GKLocalPlayerListener

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

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

然而,除了"播放器(播放器:GKPlayer,receivedTurnEventForMatch匹配:GKTurnBasedMatch,didBecomeActive:Bool)",这是所有其他方法,包括& #34;玩家(玩家:GKPlayer,matchEnded match:GKTurnBasedMatch)"这种事件发生时从未被调用过。

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

4 个答案:

答案 0 :(得分:7)

关于检测到您被邀请参加基于回合制的比赛:没有发送任何活动,但是当您从服务器查询比赛列表时,您只是突然显示一个新比赛(并且您的状态将被邀请)。 (收件人确实收到了他们收到邀请的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的反馈更新了“提醒”通知的状态。

答案 1 :(得分:1)

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

我已更新了我的TurnBasedSkeleton项目。

答案 2 :(得分:0)

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

但根据Thunk正在制作的声明,我能够获得玩家:didModifySavedGame和player:hasConflictingSavedGames,他说他从未见过他们。

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

我发现通过设置localPlayer.registerListener(self),其中self是符合要求的类,我将触发它们。

因此请仔细检查任何未使用此设置触发的方法,并告诉我们它是否更好。

答案 3 :(得分:0)

你没有遗漏任何东西。 Apple选择了

  

删除[这些]功能[s]

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

Apple bug report