小编Ani*_*nil的帖子

cordova-ionic ngCordova ios或iPhone文件读取错误代码5 ENCODING_ERR

我正在使用cordova-ionic框架来构建应用程序.我是新手中的iOS或iPhone,我必须在应用程序中读取文件.我在Android应用程序中读取文件但相同的代码显示错误(代码:5).

我遵循代码类型:

在android中:

$cordovaFile.writeFile(( 'user.json', data, {'append':false} )).then(function(result) {
  alert('file created.');
    alert(JSON.stringify(result));
}, function(err) {
    // An error occured. Show a message to the user
    alert('file writed');
    alert(JSON.stringify(err));
});
Run Code Online (Sandbox Code Playgroud)

我可以创建文件,写入,读取数据和删除文件,但在ios手机中,我无法使用相同的代码创建文件.

在iPhone中:

var data = {"user":{"name":"errer","email":"sdsdff@gmail.com","username":"sdfsdfsd"}};

$cordovaFile.writeFile(( 'user.json', data, {'append':false} )).then(function(result) {
    // Success!
    alert('file created.');
    alert(JSON.stringify(result));
}, function(err) {
    // An error occured. Show a message to the user
    alert('file writed');
    alert(JSON.stringify(err));
});
Run Code Online (Sandbox Code Playgroud)

我只是更改我的目录是cordova.file.cacheDirecotry/cordova.file.applicationDirectory

$cordovaFile.createFile(( cordova.file.cacheDirecotry+'user.json', true )).then(function(result) {
    // Success!
    alert('file created.');
    alert(JSON.stringify(result));
}, function(err) {
    // An error …
Run Code Online (Sandbox Code Playgroud)

iphone android ios cordova ionic-framework

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

cordova ×1

ionic-framework ×1

ios ×1

iphone ×1