ios - cordova-plugin-file 在 ios 上不起作用,无法将捕获的图像保存在文档目录中

标签 ios ionic3 cordova-plugin-file

我正在尝试借助 Cordova 文件插件将捕获的图像保存在文档目录中。

下面是我将文件写入文档目录的代码:

saveFile(){
    console.log("saveFile start");
    this.filename = "photo_1234.jpeg"; 
    console.log('filename:',this.filename);
    this.platform.ready().then(() => { 
      this.filePath = this.file.documentsDirectory;       
      console.log('filePath:',this.filePath);
      this.writeFile(this.selectedImage,"MyPhotos", this.filename, this.filePath);
    }); 
  }


//here is the method is used to write a file in storage  
  public writeFile(base64Data: any, folderName: string, fileName: any, filePath: any) { 
    console.log("writeFile start");
    let contentType = this.getContentType(base64Data);  
    let DataBlob = this.base64toBlob(base64Data, contentType);  
    // here iam mentioned this line this.file.externalRootDirectory is a native pre-defined file path storage. You can change a file path whatever pre-defined method.  
    this.file.writeFile(filePath, fileName, DataBlob, contentType).then((success) => {  
        console.log("File Writed Successfully", success);  
        this.saveData();
    }).catch((err) => {  
        console.log("Error Occured While Writing File", err);  
    })  
  }  

但它不起作用,并且它没有在控制台上抛出任何错误。

知道我的代码出了什么问题或者我遗漏了什么吗?

指导我解决这个问题。

提前致谢!

最佳答案

我找到了上述问题的解决方案。

这是因为插件版本不匹配“@ionic-native/core”

所以我的 "@ionic-native/core" 版本是 "4.17.0" 并且我安装了 "@ionic-native/file": "^5.14.0"

所以我们要么需要升级@Ionic-native/core版本,要么降级文件插件版本。

所以我决定降级 Ionic File 插件版本。

完成此操作后,它会按预期工作。

我从这个问题中学到了什么?

答:仅使用具有核心框架的插件受支持的版本,否则它将无法工作,也不会抛出任何错误。

Note: Don't ignore any warning logged in terminal while installing any plugin.

我发布在这里是为了其他人可以发现它有帮助。

谢谢大家调查我的问题。

关于ios - cordova-plugin-file 在 ios 上不起作用,无法将捕获的图像保存在文档目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57951696/

相关文章:

ios - firebase3在Swift中的集成面临问题

cordova - ionic 3 : black screen with Android App on device

ionic2 - ionic ionic 按钮仅图标

android - Cordova 文件插件 - 在设备中保存文件

ios - 如何使 Cordova iOS APP 动态生成/保存的文件可供最终用户访问?

ios - 无论我尝试什么,我都无法让这个应用程序匹配所有不同的设备尺寸,关于如何使用这样的约束有什么建议吗?

iOS8 : How to load xib from Dynamic Framework

ios - 调试 native 绑定(bind)库

javascript - Firebase 给出失败的先决条件错误

android - Cordova + Android Studio 报错:'com.android.build.gradle.BasePlugin' 没有实现Plugin接口(interface)