Domanda

cercando di implementare un multiplayer. Utilizzando il campione da Game Center -. Invio e ricezione di dati

Tutto sembra a posto, ma in documentazione mela v'è anche detto a proposito gestore invito.

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
   // Insert application-specific code here to clean up any games in progress.
   if (acceptedInvite) {
        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] autorelease];
        mmvc.matchmakerDelegate = self;
        [self presentModalViewController:mmvc animated:YES];
    } else if (playersToInvite) {
        GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
        request.minPlayers = 2;
        request.maxPlayers = 4;
        request.playersToInvite = playersToInvite;

        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
        mmvc.matchmakerDelegate = self;
        [self presentModalViewController:mmvc animated:YES];
    }
};

Il problema è abbastanza semplice:. Non so dove per aggiungere questo codice

È stato utile?

Soluzione

Come indicato nella documentazione

  

L'applicazione deve impostare il   handler invito fin da   possibile dopo l'applicazione è   lanciato; un luogo idoneo per set   il gestore è nel blocco di completamento   hai fornito che viene eseguito dopo la   giocatore locale è autenticato.

Da qualche parte nel codice, si dovrebbe avere autenticato il giocatore locale con qualcosa di simile

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
    if (error == nil) {
        // Insert your piece of code here
    } else {
        // Handle the error
    }
}];

La speranza che aiuta

Altri suggerimenti

Il mio codice è al di sotto, e funziona molto bene. Nel authenticateLocalUser, aggiungere il seguente codice:

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
    [GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {  // Add for invite handler
        // Insert application-specific code here to clean up any games in progress.
        if (acceptedInvite) {
            GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] ;
            mmvc.matchmakerDelegate = self;
            // [self presentModalViewController:mmvc animated:YES];
            [_delegate matchStart];
        } else if (playersToInvite) {
            GKMatchRequest *request = [[GKMatchRequest alloc] init] ;
            request.minPlayers = 2;
            request.maxPlayers = 2;
            request.playersToInvite = playersToInvite;

            GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request] ;
            mmvc.matchmakerDelegate = self;
            // [self presentModalViewController:mmvc animated:YES];
            [_delegate matchStart];
        }
    };

    [self callDelegateOnMainThread:@selector(processGameCenterAuth:) withArg:NULL error:error];
}];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top