title: Spin Lock when writing to stream iOS(only on simulator)
body: <p>I am getting a spin lock error whenever I send my application to the background. Here is the code I have when the application is minimized:</p>
  
  <pre><code>- (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];
  }
  </code></pre>
  
  <p>I am getting an EXC_BAD_ACCESS on the ouputStream write method. I am attaching screenshots as well. <img src="https://i.stack.imgur.com/bCT3U.png" alt="Image"></p>