【问题标题】:Create a remote couchdb database within ionic apps在 ionic 应用程序中创建远程 couchdb 数据库
【发布时间】:2018-07-16 05:58:01
【问题描述】:

我正在构建一个 ionic 3 应用程序,并且我正在使用 PouchDB 和 CouchDB 进行同步。 为了创建远程数据库,我使用了 official documentation 中推荐的 db.info() 命令:

注意:在您执行 API 调用之前,不会创建远程数据库,例如:db.info()。其背后的原因是 PouchDB 构造函数是完全同步的,以便于错误处理(即没有异步错误)。

这是我在应用中使用的代码:

let remotex = new PouchDB('https://' + auth + '@' + 'xxx.xx:6984/' + xx + '_xx');
return remotex
  .info()
  .then((res) => {
    console.log(res);
    return res;
  })
  .catch(function(err) {
    console.log('error : ', err);
    return err;
  });

这工作正常;当我在调试模式下构建我的应用程序时,远程数据库已创建并且同步工作良好

ionic cordova build android --prod --buildConfig

但是,在发布版本时没有创建远程数据库:

ionic cordova build android --prod --release --buildConfig

.info() 方法正在返回:

{"status":0, "name":"unknown"}

命令“.info()”是否只在调试模式下工作? 有没有其他方法可以创建远程数据库并使同步工作?

谢谢。

【问题讨论】:

  • 看来这是一个cordova问题而不是pouchdb问题,我已经发布了一个问题here,但是已经关闭了。

标签: android cordova couchdb ionic3 pouchdb


【解决方案1】:

原来是我在 CouchDB 服务器上配置的 SSL 证书的问题。证书是自签名的,因此当应用程序处于调试模式时,cordova 构建过程会忽略无效证书生成的错误。但这不是发布模式的情况。

所以我修改了应用程序在发布模式下的构建方式,以允许它发出“不安全”的请求。在为 Android 构建应用程序时,我更改了文件 SystemWebViewClient.java 位于 project/platforms/android/CordovaLib/src/org/apache/cordova/engine/ 这样:

         if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            handler.proceed();
            return;
        } else {
            // debug = false => comment this 
            //super.onReceivedSslError(view, handler, error); => comment this

            handler.proceed(); // added this
            return;
        }

这只是一种变通方法,不应在生产模式下使用。 我找到了这个解决方案here

【讨论】:

    猜你喜欢
    • 2020-12-03
    • 1970-01-01
    • 2017-11-19
    • 2011-01-30
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    相关资源
    最近更新 更多