【问题标题】:Code:1000 Can't write or create a file in my app using ionic-native/file ionic 2代码:1000 无法使用 ionic-native/file ionic 2 在我的应用程序中写入或创建文件
【发布时间】:2018-01-25 04:37:54
【问题描述】:

我现在正在开发一个致力于本地化的混合应用程序,其逻辑是用户将拥有例如 3 个选择语言的选项,我在 bluemix 上有一个 node.js 服务器来处理 cloudant-nosql db开始吧,我将我的本地 json 文件“rev”值与服务器上的另一个值进行比较,如果它们不同,那么我必须用更新的文件覆盖本地文件,我有这个结果,但我无法将此数据写入本地文件,我现在正在使用 cordova 和 ionic 2 ,

public  GetRevFromNode(SelectedLanguage,JsonDataLocal)
    {
        JsonDataLocal.subscribe(val=>{  this.LocJson=val;  })
        this.http.get('https://*********/retriev?ID=\"'+SelectedLanguage+"\"").subscribe( result=>
        { 
           if(this.LocJson['_rev']==result.json().value)
            {
                console.log("The Local Json is Updated to the latest");
                return ;
            }
            {
                console.log("Updating Json File for "+SelectedLanguage+".json .......");
                var ob=this.file.readAsText(this.file.applicationDirectory+'www/assets/i18n',"ar.json");
                ob.then(function(val){
                    console.log("ar JSON  = "+val);
                });
                this.file.createFile('file:///android_asset/www',"ess.json",true).catch(val=>{
                    console.log("Can't create because = "+JSON.stringify(val));
                });

   this.file.writeFile('file:///android_asset/www/',"index.html","\"value\":\"Please\"",{replace:true , append:false} ).catch(val=>{
                    console.log("Can't write because ="+JSON.stringify(val));
                console.log("Updating Done ...")
            }
        } );
    }

试图使用this.file.appDirectory错误也试图让它像这里一样隐式

错误是

未捕获的承诺 [object Object]
通过使用 stringify {Code:1000}

但我可以正常读取并检查文件是否正常存在,问题在于创建和写入

【问题讨论】:

    标签: javascript android ionic2 ngcordova ionic-native


    【解决方案1】:

    https://github.com/apache/cordova-plugin-file#android-file-system-layout

    问题是我无法在applicationDirectory 路径中写入,因为该路径是只读的。

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 2021-01-10
      • 1970-01-01
      • 2016-02-01
      • 2018-06-30
      • 2019-12-01
      • 1970-01-01
      • 2019-05-01
      • 2020-05-06
      相关资源
      最近更新 更多