我使用以下通常效果很好的方法在 NSFileWrapper 中解压缩数据:
- (id)decodeObjectFromWrapperWithPreferredFilename:(NSString *)p {
NSFileWrapper *wrapper = [self.fileWrapper.fileWrappers objectForKey:p];
if (!wrapper) {
NSLog(@"Unexpected error: Couldn't find %@ in file wrapper!", p);
return nil;
}
NSData *data = [wrapper regularFileContents];
NSKeyedUnarchiver *unarchiver;
@try {
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
}
@catch (NSException *exception) {
NSLog(@"exception: %@", exception);
[TestFlight passCheckpoint:@"FILE LOADING EXCEPTION!"];
UIAlertView *alertOFF = [[UIAlertView alloc]
initWithTitle:@"Corrupt"
message:@"There was an error loading a file! Please contact m@meernotes.com"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertOFF show];
}
return [unarchiver decodeObjectForKey:@"data"];
}
但是,我偶尔会遇到线路 SIGBUS 崩溃unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
。我猜这种类型的异常没有被我的异常处理程序捕获?我该如何处理此类异常以及导致它们的原因?
这是 Crashlytics 崩溃报告:
Exception Type:SIGBUSCode:BUS_ADRALN
Thread 0 Crashed
Latest Crash: 11 September 2012 at 06:23
0 Foundation
-[NSKeyedUnarchiver initForReadingWithData:] + 389
1 Meernotes ✭ FRNBDocument.m line 221
-[FRNBDocument decodeObjectFromWrapperWithPreferredFilename:] + 221
2 Meernotes FRNBDocument.m line 155
-[FRNBDocument settings] + 155
3 Meernotes ModelController.m line 497
__39-[ModelController previewLoadDocAtURL:]_block_invoke_0 + 497
4
...
libdispatch.dylib
_dispatch_barrier_sync_f_slow_invoke + 78
5 libdispatch.dylib
_dispatch_main_queue_callback_4CF$VARIANT$up + 196
6 CoreFoundation
__CFRunLoopRun + 1268
7 CoreFoundation
CFRunLoopRunSpecific + 300
8 CoreFoundation
CFRunLoopRunInMode + 104
9 GraphicsServices
GSEventRunModal + 136
10 UIKit
UIApplicationMain + 1080
11 Meernotes main.m line 16
main + 16