PhoneGap iOS,如何获取应用“文档"文件夹完整路径? [英] PhoneGap iOS, how to get app "Documents" folder full path?

查看:26
本文介绍了PhoneGap iOS,如何获取应用“文档"文件夹完整路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将照片复制到此路径中.但如何获得呢?

I need copy photo into this path. but how to get it?

iPhone Simulator/5.1/Applications/996C42CE-B8BF-4F1A-B16C-DBF194BD5A71/Documents/"

http://docs.phonegap.com/en/1.8.0/cordova_file_file.md.html#FileTransfer
我想将图像下载到我的应用程序文档文件夹中.但我不知道那个文件的完整路径.

http://docs.phonegap.com/en/1.8.0/cordova_file_file.md.html#FileTransfer
I want to download a image into my app documents folder. but I do not know the FullPath of that documents.

推荐答案

试试这个代码:

document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
        console.log("device is ready");
        window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }

    function fail() {
        console.log("failed to get filesystem");
    }

    function gotFS(fileSystem) {
        console.log("got filesystem");

            // save the file system for later access
        console.log(fileSystem.root.fullPath);
        window.rootFS = fileSystem.root;
    }

    function downloadImage(url, fileName){
        var ft = new FileTransfer();
        ft.download(
            url,
            window.rootFS.fullPath + "/" + fileName,
            function(entry) {
                console.log("download complete: " + entry.fullPath);

            },
            function(error) {
                console.log("download error" + error.code);
            }
        );
    }

gist 展示了适用于 iOS 和 Android 的实现

The gist shows the implementation which works for both iOS and Android

这篇关于PhoneGap iOS,如何获取应用“文档"文件夹完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆