【问题标题】:Ionic App - SQLite error "plugin_not_installed" only when running app in iOs devicesIonic App - 仅在 iOs 设备中运行应用程序时出现 SQLite 错误“plugin_not_installed”
【发布时间】:2018-12-22 17:46:55
【问题描述】:

我使用 Ionic3+AngularJS 构建了一个混合应用程序,它使用 SQLite 数据库。

当我在 Android 设备上运行该应用程序时,它运行良好,但当我尝试在 iPhone 或 iPad 上运行它时,我收到以下错误:plugin_not_installed。当应用程序尝试创建数据库时会发生这种情况。

这是它创建数据库的方式:

  public getDB(){
    return this.sqlite.create({
      name: 'namedatabase.db',
      location: 'default'
    }).catch( error => this.showError(error));
  }

调用 catch() 并显示错误消息“plugin_not_installed”。

SQLite 安装使用:

 $ ionic cordova plugin add cordova-sqlite-storage
 $ npm install --save @ionic-native/sqlite

有什么想法吗?

【问题讨论】:

    标签: ios iphone sqlite ionic-framework ionic3


    【解决方案1】:

    当我使用

    在 android 模拟器中运行我的应用程序时,我遇到了同样的问题

    ionic cordova 运行 android -lc

    当应用启动时,一切正常。但是在我的代码和保存命令中进行了几次更改后,应用程序重新加载并显示在我的控制台中

    console.warn: Ionic Native: deviceready 没有在 5000 毫秒内触发。当插件处于不一致状态时,可能会发生这种情况。尝试从 plugins / 中删除插件并重新安装它们。
    console.warn: 'Native: 尝试访问 SQLite 插件,但未安装。
    console.warn:安装 SQLite 插件:'ionic cordova plugin add cordova-sqlite-storage'
    console.log: 错误“plugin_not_installed”

    即使我按照控制台要求我执行的操作,我仍然会收到相同的错误并且它无法创建我的 SQLite 数据库

    我接下来要做的是使用上面的运行命令重新运行该应用程序,但是这浪费了我很多时间来等待应用程序再次启动......一次又一次:(

    createDBFile() {
        this.sqlite.create({
            name: DB_NAME,
            location: 'default'
        }).then((db: SQLiteObject) => {
            this.db = db;
            console.log('BDD cree')
            this.stockageLocal.get('dbstatus').then(opened => {
                if (opened) {
                    console.log('DB deja ouvert');
                }
                else {
                    console.log('create all table')
                    this.createTables();
                }
            })
        }).catch(err => {
            console.log(' err', JSON.stringify(err))
        });
    }
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题:plugin_not_installed。 我解决了在 promise 错误之后放置 console.log 检查并看到该表不存在。

      代码:

      this.sqlite.create({
        name: 'ionicdb.db',
        location: 'default'
      })
      .then((db: SQLiteObject) => {
        db.executeSql('create table if not exists MY_SQLITE_STORAGE(key VARCHAR(32) PRIMARY KEY, value VARCHAR(32))', [])
          .then(() => {
            console.log('Executed Create table if not exists');
            this.toastCtrl.create({
              message: 'Table created ',
              duration: 5000,
              position: 'center'
            }).present();
          }).catch(e => console.log('error: '+JSON.stringify(e)));
      }).catch(e => console.log('error: '+JSON.stringify(e)));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多