Pregunta

tratando de implementar un multijugador. Utilizando la muestra de Game Center -. El envío y recepción de datos

Todo parece bien, pero en documentación manzana existe también dijo sobre manejador de invitación.

[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];
    }
};

El problema es bastante simple:. No sé dónde agregar el código

¿Fue útil?

Solución

Como se indica en los documentos

Su aplicación debe establecer el manejador de invitación tan pronto como sea posible después de su aplicación es lanzado; un lugar apropiado para conjunto el controlador está en el bloque de terminación que siempre que se ejecuta después de la El jugador local está autenticado.

En algún lugar de su código, debería haber autenticado el jugador local con algo como esto

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

Espero que ayude

Otros consejos

Mi código está por debajo, y funciona muy bien. En el authenticateLocalUser, agregue el siguiente código:

[[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];
}];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top