【问题标题】:Phonegap file/file-transfer plugin success but no folder in iosPhonegap文件/文件传输插件成功但ios中没有文件夹
【发布时间】:2014-10-15 10:27:48
【问题描述】:

我正在尝试创建一个新文件夹“Abc”,然后将图像从 url 下载到它。它在 Android 中运行良好,我在 Gallery 中看到文件夹/图片,但在 ios 中看不到。

添加了一些警报,这让我觉得文件夹和图像在 ios 中下载得很好(触发了成功功能),但我无法在任何地方看到该文件夹​​。此外,我正在尝试从应用程序本身共享该图像,并且该功能也没有选择本地图像(同样,在 Android 中工作正常)。我在 Phonegap 3.5 中使用最新版本的文件和文件传输插件

这是我正在使用的代码:

//in onDeviceReady
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, null);    
function onFSSuccess(fileSystem) {
fileSystem.root.getDirectory("Abc",{create:true, exclusive: false},gotDir,onError);
}

function gotDir(d){
DATADIR = d;
alert(DATADIR.toURL());
}

var ft = new FileTransfer();

ft.download(imgurl, dlPath, function(entry) {
    console.log("download complete: " + entry.fullPath);
    alert(entry.fullPath);
             },
  function(error) {
    alert(error.code);
    console.log("download error source " + error.source);
    console.log("download error target " + error.target);
    console.log("upload error code" + error.code);
     }
    );

DATADIR.toURL() 返回:

安卓:

file:///storage/emulated/0/Abc/

ios:

file:///var/mobile/Applications/xxxx-xxxx-xxx-xx-xxx/Documents/Abc/

entry.fullPath 返回:

安卓:

/Abc/filename.ext

iOS:

/Abc/filename.ext

但我在 iphone (ios 7) 上的 Documents 中的任何地方都看不到“Abc”文件夹。

有什么建议吗?

谢谢!

更新:

当我在模拟器中运行它时,我可以浏览到 mac 上的新目录(通过 ~/Library/Application Support/iPhone Simulator),并且可以通过 SocialShare 插件进一步访问它,但不能在实际设备中访问它(尝试过2)。

另一个更新:

我现在可以对下载到设备新文件夹中的图像使用共享功能。但是,我仍然无法浏览创建的新文件夹。如果它正在共享,则意味着该文件夹存在但无法访问。有什么想法吗?

【问题讨论】:

    标签: ios file cordova directory


    【解决方案1】:

    检查您的 config.xml 文件,以查看您是否使用文件系统文档 (https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md) 中所述的 iosPersistentFileLocation 库。您的代码可能在库中。

    【讨论】:

    • 刚刚检查过,我没有看到为 iosPersistentFileLocation 设置任何首选项:(
    • 对不起,你把我弄到了那里。也许尝试使用 iExplorer (macroplant.com/iexplorer) 找到它?
    • 您是否知道文件夹是从应用程序创建的并且图像被保存到其中,它会在照片中显示为新相册还是对其他应用程序保持私有(独家:false)。请参阅我对帖子的第二次更新。
    • 我不这么认为。如果您查看此处的位置表 (github.com/apache/cordova-plugin-file/blob/master/doc/index.md),似乎没有一个暗示照片库。
    • Android 好多了...在任何地方下载照片,它就会显示在图库中!似乎通过 getDirectory 创建的文件夹是应用程序私有的,无法从 iPhone 外部访问。
    【解决方案2】:

    您可以使用 cordova-plugin-photo-library 将下载的图片显示到手机图库。

    https://www.npmjs.com/package/cordova-plugin-photo-library

    var url = 'file:///...';
    var album = 'MyAppName';
    
    //save Image
    cordova.plugins.photoLibrary.saveImage(url, album, function (libraryItem) {}, function (err) {});
    
    //save video
    cordova.plugins.photoLibrary.saveVideo(url, album, function () {}, function (err) {});
    

    saveImage 和 saveVideo 都需要通过 requestAuthorization 授予写入权限。

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 1970-01-01
      • 2013-11-12
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多