Phonegap 3.4 FileTransfer error (iOS)

大城市里の小女人 提交于 2019-12-24 17:26:47

问题


I'm trying to load a file from a server and save it on the device. This code used to work in Phonegap 3.1, and it's still working fine with 3.4 on Android. But when I run the same code on iOS 7.1. I got an error saying,

{
    "code":1,
    "source":"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/18/96730/70400",
    "target":null,
    "http_status":200,
    "body":"Could not create target file"
}

Here's my code.

var fileTransfer = new FileTransfer();
fileTransfer.download(encodeURI('http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/18/96730/70400'), '/com.mee.flight/maptile/70400', function (entry) {
    //Do something
});

At first I thought the solution is straight forward, since Phonegap actually tells me that there's something wrong with the target file. So, I fiddled with the file path, but they didn't really work out. Any idea?


回答1:


I figured this out already. In case anyone's having the same problem, the solution is to use 'cdvfile://localhost/persistent/' to get to the root folder in Phonegap. So, in my case, the change would be,

var fileTransfer = new FileTransfer();
fileTransfer.download(encodeURI('http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/18/96730/70400'), 'cdvfile://localhost/persistent/com.mee.flight/maptile/70400', function (entry) {
    //Do something
});


来源:https://stackoverflow.com/questions/23097188/phonegap-3-4-filetransfer-error-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!