获取phonegap中的设备绝对路径?

Moh*_*n N 4 android ios cordova

我正在使用Phonegap 3.3.0,之前我使用2.5.0,其中entry.fullPath将为设备提供完整路径.这些路径通常看起来像

/var/mobile/Applications/<application UUID>/Documents/path/to/file  (iOS)
/storage/emulated/0/path/to/file                                    (Android)
Run Code Online (Sandbox Code Playgroud)

因为该方法已被弃用,我使用entry.toURL()方法来获取路径.此方法现在将返回表单的文件系统URL

cdvfile://localhost/persistent/path/to/file
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,我将URL传递给Native函数,并从native传递文件.但是,如果我将路径传递给Native,则iOS无法检测到该文件.相同如果我对绝对路径进行硬编码,应用程序会检测到该文件.

如何使用fileSystem URL以本机或任何其他方法访问文件以获取设备的绝对路径?

提前致谢.

leo*_*leo 7

toURL()方法或nativeURL属性应该返回的结果要:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
    console.log("fileSystem.root.toURL()="+fileSystem.root.toURL());
    console.log("fileSystem.root.toInternalURL()="+fileSystem.root.toInternalURL());
    console.log("fileSystem.root.nativeURL="+fileSystem.root.nativeURL);
}, function(){
    alert("fails!");
});
Run Code Online (Sandbox Code Playgroud)

使用cordova 3.5,iPad模拟器中的输出是:

fileSystem.root.toURL()=file:///Users/myuser/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/1717CB5F-4032-45C7-8CA2-342502447F36/Documents/
fileSystem.root.toInternalURL()=cdvfile://localhost/persistent/
fileSystem.root.nativeURL=file:///Users/myuser/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/1717CB5F-4032-45C7-8CA2-342502447F36/Documents/
Run Code Online (Sandbox Code Playgroud)

...在Android模拟器(Genymotion)中是:

fileSystem.root.toURL()=file:///storage/emulated/0/ 
fileSystem.root.toInternalURL()=cdvfile://localhost/persistent/ 
fileSystem.root.nativeURL=file:///storage/emulated/0/ 
Run Code Online (Sandbox Code Playgroud)