2016-04-18 17 views
0

iOSのライブラリディレクトリに、アイフォンフレームワークを使用してアプリ内にいくつかの画像を保存しています。 Cordova-plugin-fileとCordova-plugin-fileを使って同じディレクトリを削除することはできますか?iOSのアプリのtempディレクトリをcordovaプラグインを使用して削除する

誰でも手助けできますか?

画像をダウンロードするための私のコードは次のとおりです。ここで

downloadImage: function(url, fileName) { 
     var deferred = $q.defer(); 

     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) { 
       fs.root.getDirectory(
        LOCAL_STORAGE_KEYS.app, { 
         create: true 
        }, 
        function(dirEntry) { 
         // console.log(arguments); 
         dirEntry.getFile(
          fileName, { 
           create: true, 
           exclusive: false 
          }, 
          function(fe) { 
           console.log(arguments); 

           var p = fe.toURL(); 
           console.log("In service the url path:", p); 
           fe.remove(); 
           var ft = new FileTransfer(); 
           console.log('File Transfer instance:', ft); 
           ft.download(
            encodeURI(url), 
            p, 
            function(entry) { 
             console.log('In service the entry callback:', entry); 
             if (entry && entry.toURL) { 
              deferred.resolve(entry.toURL()); 
             } else { 
              console.log('No entry:', arguments); 
              deferred.resolve(); 
             } 
            }, 
            function(err) { 
             console.log('Getting rejected:', err); 
             deferred.reject(err); 
            }, 
            false, 
            null 
           ); 
          }, 
          function() { 
           deferred.reject(new Error('get file failed')); 
          } 
         ); 
        } 
       ); 
      }, 
      function() { 
       deferred.reject(new Error('get directory failed')); 
      }); 

     return deferred.promise; 
    }  
+0

ディレクトリの名前は何ですか削除しますか? –

+0

名前はNCEC –

答えて

0

はコルドバファイルプラグインを使用してディレクトリとその内容を削除するためのサンプルコードスニペットです:

function clearDirectory() { 
    if (ionic.Platform.isAndroid()) { 
     window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemDirSuccess, fail); 
    } else { 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemDirSuccess, fail); 
    } 

    function onFileSystemDirSuccess(fileSystem) { 
     var entry = ""; 
     if (ionic.Platform.isAndroid()) { 
      entry = fileSystem; 
     } else { 
      entry = fileSystem.root; 
     } 
     entry.getDirectory("DIRECTORY_TO_DELETE", { 
       create: true, 
       exclusive: false 
      }, 
      function(entry) { 
       entry.removeRecursively(function() { 
        console.log("Remove Recursively Succeeded"); 
       }, fail); 
      }, getDirFail); 
    } 

    function getDirFail(error) { 
     navigator.notification.alert("Error"); 
    }; 

    function fail(error) { 
     navigator.notification.alert("Error"); 
    }; 
} 
+0

No Luck ..!です! iOSプラットフォーム用ですか? @Gandhi –

+0

@ alyson_216はアンドロイドとイオスの両方で動作します。両方のプラットフォームで試してテストしました。 – Gandhi

関連する問題