Ani*_*nil 5 iphone android ios cordova ionic-framework
我正在使用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 occured. Show a message to the user
alert('file writed');
alert(JSON.stringify(err));
});
Run Code Online (Sandbox Code Playgroud)
所有方式得到错误,如代码:12或代码:5
请帮我解决这个问题,或者给我一个获取应用程序文件路径的想法
div*_*duz -7
请参阅原始文档:- https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md#ios-file-system-layout
iOS 有一些目录是只读的。尝试改变你的道路。
如果它对您不起作用,请告诉我。
| 归档时间: |
|
| 查看次数: |
14919 次 |
| 最近记录: |