-(void) match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID {
NSMutableArray* grid = (NSMutableArray*)[NSKeyedUnarchiver unarchiveObjectWithData:[data bytes]];
_game.gameMap.grid = grid;
[_game updateMap:_game.localPlayer.playerFleet];
_mainGameController = [[MainGameController alloc] initMainGameControllerWithGame:_game andFrame:self.frame.size];
[self addChild:_mainGameController.containers.overallNode];
}
-(BOOL)sendMap {
NSError* error;
NSData* packet = [NSKeyedArchiver archivedDataWithRootObject:_game.gameMap.grid];
[_game.gameCenter.match sendDataToAllPlayers: packet withDataMode:GKMatchSendDataUnreliable error:&error];
if (error != nil) {
NSLog(@"error");
}
return false;
}
此代码在以下行返回错误的访问错误:
NSMutableArray* grid = (NSMutableArray*)[NSKeyedUnarchiver unarchiveObjectWithData:[data bytes]];
答案 0 :(得分:3)
unarchiveObjectWithData:
期望它的参数是NSData的一个实例。这不是[data bytes]
返回的内容。您可能只想要data
。