2015-04-02 71 views
1

我在Ionic应用程序中有以下代码行,当平台准备就绪时触发(下图)。在Chrome上进行测试时,它可以正常工作,日志会触发(“Ionic Serve Syntax”)。在我的手机上,在Safari中,什么都没有发生,基本上什么都没有发生 - 看起来数据库甚至没有打开。SQLite插件在Mac和Windows上工作,但不在电话上的Safari上

无论下面的代码工作的一个(在设备准备就绪):

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

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

如果没有正确安装数据库,它不应该在Chrome工作太那么好吗?或者我没有正确安装SQlite?

我也在一个云平台(云9)上测试它,这可能与它有关吗?

.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)"); 

    }); 
}) 

回答

2

请通过下面的行替换以下行

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

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

请尝试以下代码它是Chrome和Safari浏览器

工作210
.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)"); 

     }); 
    }) 
+0

谢谢,我明天再试! – JohnAndrews 2015-04-04 22:16:58

+0

感谢兄弟,尝试过它(但它不工作,没有用1.0替换1,它也适用于Mac上的Safari而不是移动设备上的Safari? – JohnAndrews 2015-04-05 13:41:44

+0

表示此代码在浏览器中工作,但不在移动设备上工作? – 2015-04-06 03:59:52

相关问题