发送NSData数据包时出错

时间:2013-10-05 16:26:53

标签: ios objective-c cocoa-touch

我正在创建一个向其他玩家发送整数的应用。现在我只想让它在启动时发送数据包。此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;
}

0 个答案:

没有答案