0

I am using NSKeyedArchiver / NSKeyedUnarchiver to send objects over Bluetooth from an iPad to an iPhone remote control. It works, as shown here.

However, if the remote control receives data that isn't archived (for example, a random NSString), the entire application crashes. I want to be able to say "if the data in the archive is object X, unarchive it and do the following, but ignore it otherwise".

Is there any way to handle those errors with NSKeyedUnarchiver?

Here's my code:

- (NSMutableDictionary *)unpackReceivedNSMutableDictionaryFromData:(NSData *)receivedData {
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:receivedData];
    NSMutableDictionary *receivedDictionary = [[unarchiver decodeObjectForKey:@"MyKey"] retain];
    [unarchiver finishDecoding];
    [unarchiver release];
    return receivedDictionary;
}

Any suggestions would be very welcome! This is my first time posting on StackOverflow...

Community
  • 1
  • 1
Barron
  • 1

1 Answers1

0

Okay, figured it out after a lot of debugging... I was releasing data earlier that caused an EXC_BAD_ACCESS. I used NSZombies to track where it was coming from and removed that data release.

Barron
  • 1