2017-02-07 35 views
0

我正在使用IBM MobileFirst Foundation 8.0,Ionic 2和typescript爲iOS和Android構建Cordova應用程序。IBM MobileFirst cordova jsonstore插件無需額外超時即可初始化

我已經安裝了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-jsonstorecordova-plugin-jsonstore 遺憾的混亂

+0

這是iOS和Android或僅平臺上的問題嗎? –

+0

IOS和Android –

+0

你應該把它放在platform.read()。然後..插件得到加載後,平臺準備好 –

回答

1

嘗試在'mfpjsonjsloaded'上添加一個監聽器。該事件在JSONStore插件完成加載時觸發。

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

感謝@Paul這對我有用 –

0

我注意到你正在使用cordova-plugin-jsonstore。這與cordova-plugin-mfp-jsonstore不一樣。

cordova-plugin-jsonstore是JSONStore的一個開源版本,與MobileFirst Foundation 8.0不兼容。你可以閱讀有關該不兼容的科爾多瓦插件,在這裏:https://github.com/ibm-bluemix-mobile-services/jsonstore-cordova/

相反,你應該使用官方JSONStore插件,MobileFirst基金會8.0:cordova-plugin-mfp-jsonstore,如產品文檔,在這裏描述:https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/jsonstore/cordova/

+0

對不起,我正在使用cordova-plugin-mfp-jsonstore而不是cordova-plugin-jsonstore –

+0

添加mfpjsonjsloaded監聽程序解決了我的問題 –