我通过 Bonjour 发送了一个 NSMutableArray
- (void)sendArtwork {
NSMutableArray *dataArray = [[NSMutableArray alloc] init];
NSData *imageData = [self PNGRepresentationOfImage:[bHelp getArtwork:[playerPref selectedRow]]];
[dataArray addObject:songString];
[dataArray addObject:artistString];
[dataArray addObject:imageData];
NSData *finalData = [NSKeyedArchiver archivedDataWithRootObject:dataArray];
[self.server sendData:finalData error:nil];
}
- (NSData *)PNGRepresentationOfImage:(NSImage *)image {
[image lockFocus];
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, image.size.width, image.size.height)];
[image unlockFocus];
return [bitmapRep representationUsingType:NSJPEGFileType properties:nil];
}
然后接收并取消归档
NSMutableArray *dataArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
此代码在模拟器中完美运行。但是一旦我在我的设备上运行,解压器就会抛出这个错误。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)'
如果我不发送imageData
可变数组,我不会在设备上收到错误消息。我正在使用 Bill Dudney 的 iOS 示例和 Brad Larson 的Mac 示例。