vendredi 25 mars 2016

Cordova app with SQLite database freezes after first run in iOS but works fine in Android

I use SQlite in a Cordova app built with AngularJS. I bootstrap the app onDeviceReady() and then check if a database and a specific table exist and based on the result do certain things. The app works as expected in Android but in iOS it runs the fist time and then it gets blocked on the white page of the simulator or device! Can anyone give me an insight on how to resolve this issue?

var db = window.sqlitePlugin.openDatabase(
                     // options
                     {
                         name: "users_info.db",
                         location: 2 
                     },
                         // success callback
                         function (msg) {
                           //  console.log("success: " + msg);
                            // console.log(msg);
                         },
                         // error callback
                         function (msg) {
                           //  console.log("error: " + msg);
                         }
                     );
db.transaction(function (tx) {
    tx.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name='user'", [], function (tx, result) {

        if (result.rows.length == 0) {
            console.log('theres no table with this name ');
            $scope.$apply(function () {
                $location.path('/login');
            });
            } else {
            tx.executeSql(
          "select * from user;",
          [],
          function (tx, res) {
              var row = res.rows.item(0);
              console.log(row.role);
              if (row.role == 4) {
                  $scope.$apply(function () {
                      userService.roleid = '4';
                      userService.userid = row.userid;
                      $location.path('/student');
                  });
              }
          });
           console.log('this table exists');
        }
    });
});

I have also tried the following codes to open the database but again in iOS the app freezes after the first run

var db = $cordovaSQLite.openDB({ name: "users_info.db", location: 1, iosDatabaseLocation: 'default' },
    // success callback
                         function (msg) {
                             //  console.log("success: " + msg);
                             console.log(msg);
                             console.log('success');
                         },
                         // error callback
                         function (msg) {
                              console.log("error: " + msg);
                              console.log('error');
                         }
);

Aucun commentaire:

Enregistrer un commentaire