【发布时间】:2017-06-24 08:25:01
【问题描述】:
我正在使用 IBM MobileFirst Foundation 8.0、Ionic 2 和 typescript 来构建适用于 iOS 和 Android 的 Cordova 应用程序。
我已经安装了cordova-plugin-mfp-jsonstore 和cordova-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
很抱歉造成混乱
【问题讨论】:
-
这是 iOS 和 Android 上的问题还是只有一个平台上的问题?
-
IOS和安卓都
-
你应该把它放在 platform.read().then.. 插件在平台准备好后加载
-
@suraj,我尝试过相同但没有更改。但根据mobilefirstplatform.ibmcloud.com/blog/2016/10/17/… --->github.com/robpuryear/ionic2/blob/master/myApp/src/app/… 我们可以在平台外添加 mfpjsloaded 监听器。
-
我明白了.. 因为你说它可以在超时时工作。可能是那个平台没有加载......你使用的是与 repo 相同版本的 ionic 2 吗?
标签: cordova ibm-mobilefirst ionic2 cordova-plugins jsonstore