使用phonegap访问文件系统iOS设备

时间:2014-04-14 15:39:40

标签: ios cordova fileapi

我正在使用Phonegap开发iOS应用。此应用程序应该能够从Internet下载文件,将它们存储到先前在设备中创建的目录中。 我已经为Android目标做了同样的事情,我的代码工作正常。它在手机中创建目录,下载并保存文件。 在iOS中,我的代码不起作用。我试图在网络上搜索解决方案而没有结果。

以下是代码:

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

function onDeviceReady() {
    alert("device ready");
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
}

function onFileSystemSuccess(fileSystem) {
    console.log(fileSystem.name);
    console.log(fileSystem.root.name);              
    var directoryEntry = fileSystem.root;
    directoryEntry.getDirectory("myDir", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail);
}

function onDirectorySuccess(parent) {
    console.log(parent);
    window.localStorage.setItem("directory_path",parent.toURL()+'/');
}

function onDirectoryFail(error) {
    alert("Unable to create new directory: " + error.code);
}

function fail(evt) {
    console.log(evt.target.error.code);
}

在控制台中,我可以看到此输出:

2014-04-14 17:30:11.338 XXXXXX[1511:60b] Multi-tasking -> Device: YES, App: YES
2014-04-14 17:30:11.350 XXXXXX[1511:60b] Unlimited access to network resources
2014-04-14 17:30:11.470 XXXXXX[1511:60b] [CDVTimer][file] 4.680991ms
2014-04-14 17:30:11.613 XXXXXX[1511:60b] [CDVTimer][splashscreen] 140.942991ms
2014-04-14 17:30:11.615 XXXXXX[1511:60b] [CDVTimer][TotalPluginStartup] 149.509966ms
2014-04-14 17:30:11.640 XXXXXX[1511:60b] active
2014-04-14 17:30:13.902 XXXXXX[1511:60b] Resetting plugins due to page load.
2014-04-14 17:30:14.334 XXXXXX[1511:60b] Failed to load webpage with error: The operation couldn’t be completed. (NSURLErrorDomain error -999.)
2014-04-14 17:30:14.335 XXXXXX[1511:60b] Resetting plugins due to page load.
2014-04-14 17:30:14.718 XXXXXX[1511:60b] Finished load of: file:///var/mobile/Applications/3A5B82C4-3787-442F-858F-E0850F4A6338/XXXXXX.app/www/home.html

0 个答案:

没有答案
相关问题