2015-04-02 49 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

相關問題