0

我正在制作一个向其他玩家发送整数的应用程序。现在我只想让它在启动时发送数据包。此 VC 仅在玩家找到匹配项时加载。这是代码。它提出了我制作的错误发送数据包。为什么不发送?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.totalApples = 3;
    self.matchStarted = YES;
    int tempTotalApples = self.totalApples;
    NSData *data = [NSData dataWithBytes:&tempTotalApples length:sizeof(tempTotalApples)];
    [self sendData:data];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)sendData:(NSData *)data {
    NSError *error;
    BOOL success = [match sendDataToAllPlayers:data withDataMode:GKMatchSendDataUnreliable error:&error];
    if (!success) {
        NSLog(@"Error sending init packet");
        [self matchEnded];
    }
}

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID
{
    int i = 0;
    [data getBytes:&i length:sizeof(i)];
    label.text = @"&f", self.totalApples;
}
4

0 回答 0