0

I want to make turn based mutiplayer puzzle type game.It's works fine with all functionality inlcuding get notification of any player' turn end.But in iOS 8.3 I can't get delegate method calld while player turn end .Any solution?

I also registered Listener.But it's not called.Here is code..

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {

        __weak typeof(self) weakSelf = self;
        __weak GKLocalPlayer *weakPlayer = [GKLocalPlayer localPlayer];

        weakPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
            if (viewController != nil) {
                [weakSelf showAuthenticationDialogWhenReasonable:viewController];
            } else if (weakPlayer.isAuthenticated) {
                // Player has been authenticated!
                [weakPlayer unregisterAllListeners];

                [weakPlayer registerListener:weakSelf];

        //       GKTurnBasedEventHandler *ev =
        //        [GKTurnBasedEventHandler sharedTurnBasedEventHandler];
        //       ev.delegate = self;

            } else {
                // Should disable Game Center?
            }
        };    
    }
}
nobody
  • 19,814
  • 17
  • 56
  • 77
hmdeep
  • 2,910
  • 3
  • 14
  • 22

1 Answers1

0

Since you mention ending a turn, maybe you are experiencing the bug that was introduced in IOS8.3 that broke notifications after the active player calls endTurnWithNextParticipants, as discussed here: endTurnWithNextParticipants doesn't trigger receivedTurnEventForMatch after update to iOS 8.3 and swift 1.2

A couple of work around are proposed there, but the only solution I've found that works reliably is to set up a timer loop on the non-active devices and keep reloading the match data until you see yourself become the current participant. This is what I use:

-(void)isMatchActive:(NSTimer *)timer
{
    NSString *matchID = (NSString *)timer.userInfo;

    [GKTurnBasedMatch loadMatchWithID:matchID withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
    {
        GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
        GKTurnBasedParticipant *currentParticipant = match.currentParticipant;

        if ([localPlayer.playerID isEqualToString:currentParticipant.player.playerID])
        {
            //we have become active. Call the event handler like it's supposed to be called
            [self player:localPlayer receivedTurnEventForMatch:match didBecomeActive:false];
        }
        else
        {
            //we are still waiting to become active. Check back soon
            float dTime = 5.0;
            gameController.IOS8BugTimer = [NSTimer scheduledTimerWithTimeInterval:dTime
                                                                          target:self
                                                                     selector:@selector(isMatchActive:)
                                                                     userInfo:matchID
                                                                      repeats:NO];
         }
     }];
}
Community
  • 1
  • 1
Thunk
  • 4,099
  • 7
  • 28
  • 47