title: iPhone App Crashes with dispatch_async if operation is not completed
body: <p>In my shipping iPhone App, I've used a <code>dispatch_async</code> block without issues. The App checks a web site for price updates, parses the <code>HTML</code>, updates a Core Data model accordingly, and then refreshes the table being viewed.</p>
  
  <p>In my latest App however, I've found I can crash the App by switching out of the App while the price update process is running. The differences between the first and second usage seem to me to be only that I'm calling the dispatch block from the table's <code>refreshController</code> (ie. <code>tableViewController</code>'s now built-in pull-to-refresh mechanism) and that this is now iOS7.</p>
  
  <p>Can anyone suggest to me how <code>dispatch_async</code> should be gracefully aborted under known conditions, such as the user wishing to stop the process, or if they switch apps like this and I'd like to intercept that activity to manage the block properly, please?</p>
  
  <p>If there's any good background reading on do's and don'ts with blocks, I'd be pleased to look through such links likewise - thanks!</p>
  
  <p>This is the (mostly boilerplate) dispatch_async code I'm using, for your convenience:</p>
  
  <pre><code>priceData = [[NSMutableData alloc]init];     // priceData is declared in the header
  priceURL = …     // the price update URL
  
  NSURL *requestedPriceURL = [[NSURL alloc]initWithString:[@“myPriceURL.com”]];
  NSURLRequest *urlRequest = [NSURLRequest requestWithURL:requestedPriceURL];
  
  dispatch_queue_t dispatchQueue = dispatch_queue_create("net.fudoshindesign.loot.priceUpdateDispatchQueue", NULL);   //ie. my made-up queue name
  dispatch_async(dispatchQueue, ^{
          dispatch_async(dispatch_get_main_queue(), ^{
              NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:urlRequest delegate:self startImmediately:YES];
              [conn start];
          })
  });
  </code></pre>