ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-core

ReferenceError: BMSClient is not defined

Closed this issue · 6 comments

Short description of the problem:
Initialization of BMSClient takes time and calling BMSClient.registerAuthenticationListener immediately after BMSClient.initialize throws error - "ReferenceError: BMSClient is not defined"

Solution:
Add possibility to declare success and failure functions:

/**
*@param {function} success Success callback function
*@param {function} failure Failure callback function
*@param {string} backendRoute Specifies the base URL for the authorization server
* @param {string} backendGuid Specifies the GUID of the application
*/
this.initialize = function(success, failure, backendRoute, backendGuid) {
        cordova.exec(success, failure, BMSClientString, "initialize", [backendRoute, backendGuid]);
};

Hi,
How you got this error? , I'm not sure its related,
If you look at CDVBMSClient.swift you can see that in 'registerAuthenticationListener' function, we use: (line 83)

let client = IMFClient.sharedInstance()

this will initialize the IMFClient which is a singleton, so even if the 'BMSClient.registerAuthenticationListener' will get called before you will be able to continue with no errors.
in fact even if you put it before the initialize , it should work.
(i.e

BMSClient.registerAuthenticationListener("realm", authenticationListener);
BMSClient.initialize("route", "guid");

)

I got this error by putting initialization and registration in controller that is loaded with the first view. I thought it is related to the time because after attaching registration to the button onClick event, everything is working just fine.

can you share a snippet of your code that gives you this error, so we can try to reproduce it ?

FYI, none of the methods in BMSClient are synchronous; it seems like you are doing both methods one after the other without waiting for the success/failure callback, which is why you get the 'BMS Client not initialized' error.

it turned out that putting initialization in $ionicPlatform.ready() and registration of listener in controller caused this error. After changing the way of bootstrap to the manual, everything is working fine. Sorry for misleading.

I'm happy that it's working now.