アプリケーションをバックグラウンドに送信するたびに、スピンロックエラーが発生します。アプリケーションが最小化されたときに私が持っているコードは次のとおりです。
- (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を取得しています。スクリーンショットも添付しています。