微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ionic-Native / SQLite插件在实际的Android设备中不起作用

如何解决Ionic-Native / SQLite插件在实际的Android设备中不起作用

最近,我正在基于Ionic和Cordova的混合移动应用程序中工作。

The versions installed in my project are as follows:

ionic = 3.9.2
node = v8.9.4
npm = 5.6.0

Angular CLI: 1.6.7
Node: 8.9.4`enter code here`
OS: win32 x64
Angular: 5.2.11
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 7.3.10
@angular-devkit/schematics: 7.3.10
@schematics/angular: 8.3.29
typescript: 2.6.2
webpack: 3.8.1



 My aim of work is to save user data for offline use. To solve this purpose I installed the following plugins:
    
    npm i --save @ionic-native/sqlite@4
    npm i --save cordova-sqlite-storage@4
    
    As my volume of offline data will be a big one I decided to go with sqlite database.
    As a first attempt I tried ionic storage with a combination of localstorage option but that did not work,as after sync half of data it is showing “Quota exceeded” error. The reason I found is local storage having a storage capacity of 5MB max.
    
    Currently when I implemented the sqlite database approach what I experienced is in nested call back the execution get lost and there is no response comes after that even no error in console log too. This issue I’m facing only when running the App from the real android device (A Tablet (android version installed
    Lollipop 5.1.1 API level 22). While running from the emulator there is no such issues and all works fine.
    
    Let me explain my code execution

I placed a API call to get some data from server the API call reside under a Service (for Example Service1.ts)

Once I received data from API call I call a function to save the data in offline database. This function body again reside under another Service (for Example Service2.ts)

In my case Service1.ts ----> call API —> get response —> call Service2.ts (specific function to save offline data)

The function I’m using for saving offline data is as follows:

databaSEObj.open()。then(function(){ databaSEObj.executesql(this.queryToDelete,[Field_1_value])。then(function(deleteresponse){ console.log(deleteresponse); this.queryToDelete =‘’; databaSEObj.executesql(this.singleDBQuery,[Field_1_value])。then(function(insertresponse){ console.log(“数据已保存”); this.singleDBQuery =‘’; console.log(insertresponse); } .bind(this))。catch((inserterror)=> { console.log('数据保存错误:’+ inserterror.message); }) } .bind(this))。catch((deleteerror)=> { console.log('数据删除错误:’+ deleteerror.message); }); } .bind(this))

The reason I used bind because while debugging the code attached with real device I found in this function scope after calling the databaSEObj.open() I lost the reference of this keyword. Then it only points to windows.
Using bind solved my purpose of retain ‘this’ value but databaSEObj.executesql not giving any response as well as error.

Any suggestion from anyone of the team is really appreciated. As I’m in some strict release plan for this work and this thing is not working at all.

If coding approach wise I’m doing any wrong approach please correct that area also.

Regards,Sounak

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。