【发布时间】:2015-01-07 15:40:16
【问题描述】:
我正在使用 cordova-ionic 框架来构建应用程序。我是 iOS 或 iPhone 的新手 在我的要求中,我必须读取应用程序中的文件。我正在阅读 android 应用程序中的文件,但相同的代码显示错误(代码:5)。
我正在关注代码类型:
在安卓中:
$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));
});
我可以创建文件、写入、读取数据和删除文件,但在 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));
});
我只是改变我的目录是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 occured. Show a message to the user
alert('file writed');
alert(JSON.stringify(err));
});
一直得到错误,如代码:12 或代码:5
请帮我解决这个问题或给我一个想法来获取应用程序文件路径
【问题讨论】:
标签: android ios iphone cordova ionic-framework