Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用cordova插件在iOS中删除应用程序的临时目录_Javascript_Ios_Angularjs_Cordova_Ionic Framework - Fatal编程技术网

Javascript 使用cordova插件在iOS中删除应用程序的临时目录

Javascript 使用cordova插件在iOS中删除应用程序的临时目录,javascript,ios,angularjs,cordova,ionic-framework,Javascript,Ios,Angularjs,Cordova,Ionic Framework,我正在使用ionic framework将我的应用程序中的一些图像存储在iOS的库目录中。是否可以使用Cordova插件文件和Cordova插件文件传输删除同一目录 有人能帮忙吗 我下载图像的代码是: downloadImage: function(url, fileName) { var deferred = $q.defer(); window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function

我正在使用ionic framework将我的应用程序中的一些图像存储在iOS的库目录中。是否可以使用Cordova插件文件和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;
    }    

以下是使用cordova文件插件删除目录及其内容的示例代码段:

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");
    };
}

以下是使用cordova文件插件删除目录及其内容的示例代码段:

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");
    };
}

你想删除的目录名是什么?你想删除的目录名是什么?不走运。。!是针对iOS平台的吗@Gandhi@alyson_216适用于android和ios。在两个平台上都进行了尝试和测试。运气不好。。!是针对iOS平台的吗@Gandhi@alyson_216适用于android和ios。在两个平台上都进行了尝试和测试。