简体   繁体   中英

SQLite Plugin working on Mac and Windows but not in Safari on Phone

I have the following line of code, in an Ionic app, that fires when the platform is ready (below). When testing it on Chrome, it works fine and the log fires ("Ionic Serve Syntax"). On my mobile phone, in Safari, nothing happens, basically nothing fires - seeming like the database does not even open.

Neither one of the following codes work (after device is ready):

db = window.openDatabase("starter.db", "1.0", "My app", -1) // Nope

db = $cordovaSQLite.openDB("starter.db"); // Nope

If the database was not installed correctly, it should not work in Chrome too then right? Or did I not install the SQlite correctly?

I am also testing it on a Cloud platform (cloud9), could that have something to do with it?

.run(function($ionicPlatform, $cordovaSQLite, DebugConsole) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }

    if(window.cordova) {
      // App syntax
      console.log("App syntax")
      db = $cordovaSQLite.openDB("starter.db");
      $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
    } else {
      // Ionic serve syntax
      console.log("Ionic serve syntax")
      db = window.openDatabase("starter.db", "1.0", "My app", -1);
      $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
    }

    //$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS team (id integer primary key, name text)");

  });
})

Please Replace following line

          db = window.openDatabase("starter.db", "1.0", "My app", -1);

by following line

        db = window.openDatabase("starter.db", '1', 'My app', 1024 * 1024 * 100); // browser 

please try following code it work for both Chrome and Safari

    .run(function($ionicPlatform, $cordovaSQLite, DebugConsole) {
      $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
          cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
          // org.apache.cordova.statusbar required
          StatusBar.styleDefault();
        }

        if(window.cordova) {
          // App syntax
          console.log("App syntax")
          db = $cordovaSQLite.openDB("starter.db");
          $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
        } else {
          // Ionic serve syntax
          console.log("Ionic serve syntax")
          db = window.openDatabase("starter.db", '1', 'My app', 1024 * 1024 * 100); // browser 
         // db = window.openDatabase("starter.db", "1.0", "My app", -1);
          $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
        }

        //$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS team (id integer primary key, name text)");

      });
    })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM