title: App cache iOS PhoneGap
body: <p>On Android I used  </p>
  
  <pre><code>file:///storage/sdcard0/Android/data/my.app.id/cache/
  </code></pre>
  
  <p>to download (<a href="http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#FileTransfer" rel="nofollow noreferrer">FileTransfer</a>) some images and then show them in my html. Images and everything else inside this folder gets removed when deleting my app, which is exactly what I want. </p>
  
  <p><strong>How to achieve this on iOS?</strong></p>
  
  <p>I tried with </p>
  
  <pre><code>file:///var/mobile/Applications/&lt;GUID of app&gt;/Documents/
  </code></pre>
  
  <p>since this is what I got when requesting file system, but the images won't even download (error code 1). Any ideas? I found out more about my error: it's the same error as stated in <a href="https://stackoverflow.com/questions/9547894/the-operation-couldn-t-be-completed-cocoa-error-512">this</a> question. (Could not create path to save downloaded file - Cocoa Error 512)</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p><strong>More info:</strong>
      Relevant plugins I use are</p>
  
  <pre><code>&lt;gap:plugin name="org.apache.cordova.file" /&gt;
  &lt;gap:plugin name="org.apache.cordova.file-transfer" /&gt;
  </code></pre>
  
  <p>and features:</p>
  
  <pre><code>&lt;feature name="File"&gt;
      &lt;param name="android-package" value="org.apache.cordova.file.FileUtils" /&gt;
  &lt;/feature&gt;
  &lt;feature name="File"&gt;
      &lt;param name="ios-package" value="CDVFile" /&gt;
  &lt;/feature&gt;
  &lt;feature name="FileTransfer"&gt;
      &lt;param name="ios-package" value="CDVFileTransfer" /&gt;
  &lt;/feature&gt;
  </code></pre>
  
  <p>I download images successfully in Android with:</p>
  
  <pre><code>var fileTransfer = new FileTransfer();    
  var uri = encodeURI("myserverurl/"+fileName); 
  var filePath = appCachePath+fileName;  
          fileTransfer.download(
              uri,
              filePath,
              function(entry) {
                  alert("download complete: " + entry.fullPath); 
              },
              function(error) {  
                  alert("download error source/target/code:\n" + error.source +" \n||| "+error.target+" \n||| "+error.code); 
              }  
          );
  </code></pre>
  
  <p>I download them AFTER I successfully get FS with</p>
  
  <pre><code>function onDeviceReady() { 
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); 
      if(device.platform === 'Android'){
          cacheFolderSubPath = "Android/data/id.app.my/cache/";  
      }
      else{
          cacheFolderSubPath =  ""; //  for iOS what ??   
      }  
  }
  
  function gotFS(fileSystem) {    
      var nturl = fileSystem.root.toNativeURL();  // returns cdvfile://localhost/persistent/ for both iOS and Android 
      window.resolveLocalFileSystemURL(nturl+cacheFolderSubPath, onResolveSuccess, onResolveFail);  
  }
  
  function onResolveSuccess(fileEntry) { 
       // this is "file:///..." string mentioned in the question above.
      appCachePath = fileEntry.toNativeURL()+"/";  
      // etc etc etc ... (use this appCachePath with download code above)
  }
  </code></pre>