【问题标题】:IBM MobileFirst cordova jsonstore plug-in not initializing without extra timeoutIBM MobileFirst cordova jsonstore 插件在没有额外超时的情况下无法初始化
【发布时间】:2017-06-24 08:25:01
【问题描述】:

我正在使用 IBM MobileFirst Foundation 8.0、Ionic 2 和 typescript 来构建适用于 iOS 和 Android 的 Cordova 应用程序。

我已经安装了cordova-plugin-mfp-jsonstorecordova-plugin-mfp,但是当尝试使用下面的代码初始化 JSONStore 集合时它不起作用。我收到一条错误消息,说 JSONStore 是 undefined

mfpJSONStorageConnector.initGlobalCollections()

如果我在timeout 中添加相同的代码,如下所示,我得到WL.JSONStore[object Object]mfpJSONStorageConnector.initGlobalCollections() 工作正常。

setTimeout(function(){ 

}, 8000);

如果我删除 settimeout ,应用程序将中断,mfpJSONStorageConnector.initGlobalCollections 将无法工作

例如:

constructor(public platform: Platform, public alertCtrl: AlertController, public events: Events, 
    public renderer : Renderer, 
    public mfpJSONStorageConnector: MFPJSONStorageConnector) {

let self = this;

platform.ready().then(() => {
  StatusBar.styleDefault();  

});

self.renderer.listenGlobal('document', 'mfpjsloaded', () => {


          setTimeout(function(){ 

          mfpJSONStorageConnector.initGlobalCollections().then(function(status) {

              authenticationService.getLastLoggedInUser().then((lastLoggedInUser) => {

                   Splashscreen.hide();

              }).catch((ex) => {
                  //Error
              });  
          });  
    }, 8000);

    });

更新 我正在使用 cordova-plugin-mfp-jsonstore 而不是 cordova-plugin-jsonstore 很抱歉造成混乱

【问题讨论】:

标签: cordova ibm-mobilefirst ionic2 cordova-plugins jsonstore


【解决方案1】:

尝试在“mfpjsonjsloaded”上添加一个监听器。当 JSONStore 插件完成加载时会触发该事件。

renderer.listenGlobal('document', 'mfpjsonjsloaded', () => {
  console.log('--> MFP JSONStore API init complete');
  ...
}

【讨论】:

    【解决方案2】:

    我注意到您使用的是cordova-plugin-jsonstore。这与cordova-plugin-mfp-jsonstore 不同。

    cordova-plugin-jsonstore 是 JSONStore 的开源版本,与 MobileFirst Foundation 8.0 不兼容。您可以在此处阅读有关此不兼容 Cordova 插件的信息:https://github.com/ibm-bluemix-mobile-services/jsonstore-cordova/

    相反,您应该使用 MobileFirst Foundation 8.0 的官方 JSONStore 插件:cordova-plugin-mfp-jsonstore,如产品文档中所述,此处:https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/jsonstore/cordova/

    【讨论】:

    • 抱歉我使用的是cordova-plugin-mfp-jsonstore而不是cordova-plugin-jsonstore
    猜你喜欢
    • 2016-04-07
    • 2016-11-12
    • 2020-01-25
    • 2014-01-06
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    相关资源
    最近更新 更多