gpt4 book ai didi

iphone - 从 Game Center 发送和接收数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:03 27 4
gpt4 key购买 nike

我在通过 Game Center 多人游戏在设备之间发送数据时遇到了很多问题。我可以建立匹配并连接两个用户,但由于某种原因我无法发送数据。这是我的代码:

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

有什么想法吗?

最佳答案

您必须将当前 View Controller 分配给您的匹配委托(delegate),否则 match:didReceiveData:fromPlayer: 将无法工作。

关于iphone - 从 Game Center 发送和接收数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10923385/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com