每当我将应用程序发送到后台时,我都会收到自旋锁错误。这是我最小化应用程序时的代码:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
if (savedResults || savedSchedule || watchingClasses || professors) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
NSString *fullPath = [docDir stringByAppendingFormat:@"/%@", kFileName];
NSMutableArray *array = [NSMutableArray arrayWithCapacity:4];
if (!savedResults) {
[array addObject:[NSNull null]];
}else {
[array addObject:savedResults];
}
if (!savedSchedule) {
[array addObject:[NSNull null]];
}else {
[array addObject:savedSchedule];
}
if (!watchingClasses) {
[array addObject:[NSNull null]];
}else {
[array addObject:watchingClasses];
}
if (!serverAnnouncements) {
[array addObject:[NSNull null]];
}else {
[array addObject:serverAnnouncements];
}if (!professors) {
[array addObject:[NSNull null]];
}else {
[array addObject:professors];
}
[NSKeyedArchiver archiveRootObject:[array copy] toFile:fullPath];
}
//close connection
if (outputStream) {
if ([outputStream hasSpaceAvailable]) {
dispatch_queue_t task = dispatch_queue_create("Close Connection", nil);
NSString *str = @"_CLOSE_CONNECTION*\n";
NSData *dataToSend = [[NSData alloc] initWithData:[str dataUsingEncoding:NSUTF8StringEncoding]];
dispatch_async(task, ^{
[outputStream write:[dataToSend bytes] maxLength:[dataToSend length]];
});
}
}
[inputStream close];
[outputStream close];
inputStream = nil;
outputStream = nil;
[inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
initializedSocket = NO;
[FlurryAds setAdDelegate:nil];
}
我在 ouputStream 写入方法上得到一个 EXC_BAD_ACCESS。我也附上截图。