[SOLVED] iOS, block application while opening database


#1

Hi,

I’m working on an ionic app. I use PouchDB to store my data in order to have an offline mode.
I’m currently having trouble with the iOS version.

When I open my dataBase with this command :

new PouchDB('XXXXXXDB', {adapter : 'websql', auto_compaction : true, revs_limit : 1, location:'default', iosDatabaseLocation:'default'})

I have this in my logs :

 2016-05-20 18:14:47.225 SGNews[6944:187465] OPEN database: _pouch_laMatinaleDB
 2016-05-20 18:14:47.225 SGNews[6944:187465] new transaction is waiting for open operation
 2016-05-20 18:14:47.227 SGNews[6944:187495] Good news: SQLite is thread safe!
 2016-05-20 18:14:47.230 SGNews[6944:187465] DB opened: _pouch_laMatinaleDB

This is telling me that the database was opened, but I have no return from the promise. This makes my app blocked, even my spinner is not moving.

To reproduce this issue, I open and close my app until I get it.

I know that is a pretty awful way, but some people who use it normally have the same problem.

I use the 5.3.2 release version of PouchDB. (Everything is great on Android)


#2

Are you using the SQLite plugin? If so, make sure your not making calls to the DB before $ionicPlatform.ready. You may be creating a race condition where the plugin is not yet initialized when you make the first query.


#3

I thought I did it in the way, but when I looked furthermore it wasn’t really the case.

Thank you for your answer.

I will make some tests and I will be back to validate your answer.


#4

The error was from this. But the $ionicPlatform.ready wasn’t sufficient enough, I had to add a $timeout in order to not have this issue anymore.

Thanks for your help.


#5

I got an answer from issue for Cordova-sqlite-storage I use. (Cordova-sqlite-storage issue opened)

They told me to look after location and iosDatabaseLocation options. After reading more about it, I found that location for iOS is still available even if it’s deprecated. So, I think there is some troubles when you set location and iosDatabaseLocation in the same options. I did this in order to not have to test the platform and just have one line of code for opening my database.

After I separate the location and iosDatabaseLocation, it seems to be great.


#6

That wasn’t really a good answer. Even if the results are better, It’s not concluant.
I’m waiting for almost 5 seconds after the deviceready event to be sure to not freeze my app.

if someone can help me out, I will be grateful.