Cordova 3.3 - fileSystem.root.fullPath返回“/”而不是完整路径 [英] Cordova 3.3 - fileSystem.root.fullPath returns "/" instead of full path

查看:159
本文介绍了Cordova 3.3 - fileSystem.root.fullPath返回“/”而不是完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码使用Cordova 2.7。我已将我的应用程序升级到Cordova 3.3,同时升级了我开发的所有自定义插件。

I had a piece of code working with Cordova 2.7. I upgraded my app to Cordova 3.3 along with upgrading all the custom plugins I developed.

我成功地获得了iOS上的Documents目录的完整绝对路径2.7,但是与Cordova 3.3它只是返回 / 为fullPath

I was successfully able to get the full absolute path of the Documents directory on iOS with Cordova 2.7, but with Cordova 3.3 it just returns / for the fullPath

这是我的代码:

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

function gotFS(fileSystem) {
    alert("entered gotFS: " + fileSystem.root.fullPath);
}

我在iPad Simulator 7.0上测试了这个功能)

I tested this on iPad Simulator 7.0 (which was giving correct results with Cordova 2.7)

虽然我可以通过其他方法获取路径,但我更喜欢使用Cordova API。

Although, I can get the path with other methods, I would prefer to use the Cordova API.

API文档没有提及任何内容。

The API documentation doesn't mention anything about this. Any idea what could be wrong?

推荐答案

由于很少有用户请求我的回答,这里是我设法得到文档目录路径:

Since few users requested for my answer, here is how I managed to get the Documents directory path:

var documentsDirectoryPath = decodeURIComponent(window.location.href);
documentsDirectoryPath = documentsDirectoryPath.substring("file://".length);
documentsDirectoryPath = documentsDirectoryPath.substring(0, documentsDirectoryPath.indexOf("/<<YOUR_APP_NAME>>.app/www/index.html"));
documentsDirectoryPath += "/Documents";

请务必将 YOUR_APP_NAME 替换为应用程式名称

Remember to replace YOUR_APP_NAME with your app's name

这篇关于Cordova 3.3 - fileSystem.root.fullPath返回“/”而不是完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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