I have read on another post (Archiving / Unarchiving results in initForReadingWithData incomprehensible archive) that you can't store more than 250kBytes on a NSMutableArray. Unfortunately, in order to recover such data with NSKeyedUnarchiver, you must use a NSMutableArray. I am trying to get back an image with a size around 500kB.
MTMessage *message = [NSKeyedUnarchiver unarchiveObjectWithData:data];
The error 开发者_如何学编程I get is :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x0, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x0, 0x1)'
Apparently it's a pretty common situation (even-though i have not found a solution yet). Would you have any idea of how to bypass the use of NSMutableData. Thank you.
EDIT : Actually it says that data has a size of 524 288 bytes, which is correct, so the problem might come from the unarchiver.
NSKeyedArchiver
does not depend on an NSArray
(immutable or not).
I'm also not aware of a bug correlated with NSKeydArchiver and depending on archive size.
The following code runs fine on Lion:
NSMutableData *data = [NSMutableData data];
for (uint32_t i = 0; i < 1024 * 1024; ++i)
[data appendBytes:&i length:sizeof(uint32_t)];
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:[NSMutableArray arrayWithObject:data]];
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
assert([data isEqual:[array lastObject]]);
Please provide more code for more insight in your actual problem. Are you maybe trying to unarchive an encoded image instead of an archive?
精彩评论