title: Prevent iOS QuickLook from generating a cache
body: <p>I'm using the <a href="http://developer.apple.com/library/ios/#documentation/QuickLook/Reference/QuickLookFrameworkReference_iPhoneOS/_index.html" rel="nofollow">QuickLook Framework</a> in my iOS app to preview various files. I recently noticed that QuickLook is keeping a cache of all previewed files in my app's <code>tmp</code> directory. There are two issues with QuickLook caching files though:</p>
  
  <ol>
  <li><p>These cached files are already stored in the Documents directory. So in theory the app could double in size if the user wants to preview all of their files (which they probably will). Okay, no big deal, I can periodically clean out the cache using this code:</p>
  
  <pre><code>NSFileManager *fileMgr = [NSFileManager defaultManager];
  NSArray *fileArray = [fileMgr contentsOfDirectoryAtPath:NSTemporaryDirectory() error:nil];
   for (NSString *filename in fileArray)  {
      [fileMgr removeItemAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:filename] error:NULL];
  }
  </code></pre></li>
  <li><p>The second, and <strong>most important issue</strong> is that QuickLook seems to be creating a secondary cache in a system folder (not my app). This is an issue because users have the option to encrypt individual files in my app. If they preview a file before encrypting, it looks normal. If they encrypt and then preview afterwards, the file still appears as if it was not encrypted. I know there is not a problem with the encryption because the encrypted file stored in my app's <code>Documents</code> directory is encrypted and can't be read (properly) by any program. This is a major issue, as it may cause the user to believe the file was not encrypted. It is also a security issue because it means that QuickLook is caching the file elsewhere.</p></li>
  </ol>
  
  <p>Here is my QuickLook code:</p>
  
  <pre><code>- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
      return 1;
   }
  
  - (id &lt;QLPreviewItem&gt;)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      //Get the stored user data and file name
      NSString *FileName = [defaults objectForKey:@"FileName"]; //Name of file stored in NSUserDefaults
      NSString *finalFilePath = [documentsDirectory stringByAppendingPathComponent:FileName];
  
      return [NSURL fileURLWithPath:finalFilePath];
  }
  
  - (IBAction)previewFile:(id)sender {
     //Setup QuickLook
     QLPreviewController *previewController = [[QLPreviewController alloc] init];
     previewController.delegate=self;
     previewController.dataSource=self;
     previewController.currentPreviewItemIndex = 0;
     [previewController reloadData];
     [self presentModalViewController:previewController animated:YES];
     [previewController.navigationItem setRightBarButtonItem:nil];
  }
  </code></pre>
  
  <p>Does anyone know where the QuickLook cache is, or if there is one (maybe it's some kind of bug)?</p>
  
  <p><strong>How can I prevent QuickLook from caching files, or how can I reset the cache?</strong> If neither of these are possible is there an iOS 6 alternative to QuickLook (I've heard QuickLook was changed in iOS 6 so there aren't any workarounds, alternatives, etc.)?</p>
  
  <p>Any solutions or ideas appreciated!</p>