Gamecenter ios 9 GameCenter GKLocalPlayerListener methods not called

This is roughly a GameCenter .

Since the " GKLocalPlayerListener protocol inherits methods from GKChallengeListener , GKInviteEventListener and GKTurnBasedEventListener .

To handle multiple events "and" do not execute GKChallengeListener , GKInviteEventListener and GKTurnBasedEventListener directly; GKLocalPlayerListener instead.

You can listen and handle several events using the GKLocalPlayerListener "(this is from Apple docs).

One would expect that after registering the GKLocalPlayerListener after the authentication of GKLocalPlayer.localPlayer() all methods in the GKLocalPlayerListener will be called when the corresponding events occur.

However, except for "player (player: GKPlayer , receivedTurnEventForMatch matches: GKTurnBasedMatch , didBecomeActive: Bool)", which is called, all other methods, including "player (player: GKPlayer , matchEnded match: GKTurnBasedMatch )", are never called when such an event occurs .

Do I need to register another listener or is there something that I am missing?

+5
source share
4 answers

Regarding the discovery that you were invited in a step-by-step correspondence: no event has been sent, but when you request a list of matches from the server, you just have a new match (and your status will be invited). (the recipient does receive the UIAlert invitation that they received the invitation, though)

Regarding when / when the various API functions start, I spent many, many, many hours trying to decrypt when these various functions are triggered. I discovered more than a few errors, either against functions or against documentation. Here are my current notes; This is how I organized all the delegate functions in my helper class, indicating which listener they belong to, as well as notes on what makes them run.

You can see that there are several that I have never decoded. Any additional input / clarification on this list would be greatly appreciated.

 #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 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) */ 

Edit: Updated reminder notification status based on μ4ρκ05 feedback.

+6
source

Well, your list and explanation of the various methods made me think. Primarily. The problem of receiving notification when receiving compliance is one of the most pressing problems for me, because if you do not receive notification, it means that you will need to pull data. So when do you load the matches again? Every x seconds, or every time a view controller appears with a list of games? Both will make unnecessary network calls that will be annoying, and also because the list of games may need to be reloaded, without any actual changes, it may not look very good. Therefore, at first I thought about using exchanges so that the opponent could receive a notification and restart the games. However, after reading the message, I remembered player receives a reminder (UNTESTED) , which is called receivedTurnEventForMatch . Now I managed to get an option notified about a new game by initializing a new game, turning and sending a reminder.

I updated the TurnBasedSkeleton project.

+1
source

I don't have a reputation high enough to comment on Thunks answer, but I can submit my own, so that’s how I get this information there. Most of the problem is that there are no examples of how to use this code, but no documentation. Thus, a code that does not work is not proof that the code is broken, we just don’t know how to use it.

But based on the statements that Thunk makes, I was able to get a player: didModifySavedGame and player: hasConflictingSavedGames, who, he said, had never seen their fire.

These are the GKSavedGameListener insanity methods. The problem that I encountered with this protocol is that it does not have a delegate for its appointment, so I can select any class in my program and bring it into line with this protocol, and then expect the methods to be launched, which seemed unlikely. So I need some kind of delegate to say which class matches.

I found that by setting localPlayer.registerListener (self), where self is the appropriate class, I force them to fire.

So, double check any methods that don't fire with this kit, and let us know if it works better.

0
source

You are missing nothing. Apple chose

remove [these] functions [s]

I opened a message with Apple for further investigation. Their answer was unsatisfactory, to say the least.

Apple Bug Report

0
source

Source: https://habr.com/ru/post/1239129/


All Articles