cordova.file.* (all directories) are null

做~自己de王妃 提交于 2020-01-11 09:42:42

问题


I'm working on Ionic mobile app development.

My requirement is to create client side logger to track issues in app. I used the methods mentioned in https://github.com/pbakondy/filelogger, and I could able to create the log file in both Android and iOS.

For the first time when I open the app, it creates the log file in cordova.file.dataDirectory, when I close and reopen the app in i*OS, I'm trying to read the content of the file which was created using the below

$fileLogger.getLogfile().then(function (loggerContent) {
                    var temp =loggerContent;
                });

But the application says

{ 
"applicationDirectory":null,
"applicationStorageDirectory":null,
"dataDirectory":null,
"cacheDirectory":null,
"externalApplicationStorageDirectory":null,
"externalDataDirectory":null,
"externalCacheDirectory":null,
"externalRootDirectory":null,
"tempDirectory":null,
"syncedDataDirectory":null,
"documentsDirectory":null,
"sharedDirectory":null
}

So I couldn't able to find the file where i saved my logs.

Please help me resolve this issue or if you could recommend me a different method to get around this issue, that would be great!

Thanks for the answers


回答1:


There is a check list here and should solve your problem :

1-Be sure that the cordova-file-plugin is installed and works in your test environment.

2-Be sure that the cordova.js file is refrenced by your html and before your code usage.

3-Be sure to call your codes after device_ready state : check this

4-Call your function after a short delay (use setTimeOut in Javascirpt)




回答2:


Ali's item 4 is very important: I had a similiar problem on different platforms: cordova.file.dataDirectory was null. I tracked cordova.file.dataDirectory over the lifecycle and it was first accessed by my Ionic 2 code BEFORE the device ready event was fired. My "mistake": I wanted to load data during the constructor(!) of a service. Seems too early.



来源:https://stackoverflow.com/questions/39515414/cordova-file-all-directories-are-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!