【问题标题】:SQLite Plugin working on Mac and Windows but not in Safari on PhoneSQLite 插件可在 Mac 和 Windows 上运行,但不能在手机上的 Safari 中运行
【发布时间】:2015-06-07 12:50:18
【问题描述】:

我在 Ionic 应用程序中有以下代码行,当平台准备好时会触发(如下)。在 Chrome 上测试它时,它工作正常并且日志触发(“离子服务语法”)。在我的手机上,在 Safari 中,什么都没有发生,基本上没有任何反应 - 似乎数据库甚至没有打开。

以下任一代码均无效(设备准备就绪后):

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

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

如果数据库没有正确安装,那么它也不应该在 Chrome 中运行,对吧?还是我没有正确安装 SQlite?

我也在云平台(cloud9)上测试,会不会和它有关?

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

  });
})

【问题讨论】:

    标签: javascript sqlite cordova phonegap-build ionic


    【解决方案1】:

    请替换下一行

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

    以下行

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

    请尝试以下适用于 Chrome 和 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)");
    
          });
        })
    

    【讨论】:

    • 谢谢,我明天试试!
    • 谢谢老哥,试过了(但是如果不把1换成1.0就不行,在mac上的Safari上也行,但在移动设备上不行?
    • 表示此代码在浏览器中有效,但在移动设备中无效?
    • 适用于设备(​​安装后)以及计算机上的 Chrome 和 Safari,但不适用于设备上的 Safari
    • 为什么要参考设备浏览器来测试混合应用程序,它适用于小型测试,但不建议用于更复杂的应用程序。有关更多详细信息,请阅读以下链接上的 ionic 框架移动浏览器测试指南 -@987654321 @
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多