2

ゲームセンターのマルチプレイヤーからデバイス間でデータを送信するのに多くの問題があります。一致を確立して両方のユーザーを接続できますが、何らかの理由でデータを送信できません。これが私のコードです:

-(void)sendData {
    NSError *error;
    int myScore = scoreInt;
    NSData *packet = [NSData dataWithBytes:&myScore length:sizeof(myScore)];
    [theMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error: &error];
    if (error != nil)
    {
        NSLog(@"ERROR: %@", error);
    }    
}

-(void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID {

    NSLog(@"called");

}

別のビューから試合を行っていますが、それが問題かどうかはわかりませんが、ゲームセンターが試合を見つけたときのコードは次のとおりです。

 - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
    MultiplayerView *mpv = [[MultiplayerView alloc] init];

    [self dismissModalViewControllerAnimated:NO];

    mpv.theMatch = match; // Use a retaining property to retain the match.

    match.delegate = self;

    NSLog(@"Matched");
    if (!self.matchStarted && match.expectedPlayerCount == 0)
    {
        self.matchStarted = YES;
        NSLog(@"Lets Go");
        MultiplayerView *mpv = [[MultiplayerView alloc] init];
        [mpv setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentModalViewController:mpv animated:YES];
    }
}

何か案は?

4

1 に答える 1

1

現在のビュー コントローラーをマッチ デリゲートに割り当てる必要があります。そうしないと、match:didReceiveData:fromPlayer: が機能しません。

于 2012-10-12T07:54:23.003 に答える