简体   繁体   中英

How to initialize Kony Fabric client

I am new to the platform and having problems in initializing Kony Fabric client and using the integration services. Is there any link or reference?

You can refer the documentation where it has been mentioned very nicely. To manually initialize the kony fabric client:

//Sample code to initialize Kony Fabric Client
var appkey = <your-app-key>
var appsecret = <your-app-secret>
var serviceURL = <your-service-url>

var client = new kony.sdk();
client.init(appkey, appsecret, serviceURL, function(response) {
    kony.print("Init success");
}, function(error) {
    kony.print("Init Failure");
});

You can use client to use the servcies. However manual intialization is not recommended. You should always should always use initWithServiceDoc See the link for more information:

http://docs.kony.com/konylibrary/konyfabric/kony_fabric_user_guide/Content/KonyStudio/Installing_KonyJS_SDK.htm

You don't really have to explicitly initialize. This is an unnecessary headache for the reasons explained below.

Also personally I would not recommend hardcoding the API key and secret. Though you may find examples of that in the documentation, Kony ( now Temenos Quantum ) actually does not recommend this.

Reasons this is not recommended:

  1. You will have trouble when you unpublish the application in Fabric and publish again, because the key and secret will change. This is going to cause issues because you have to modify the code again and build the WAR files and binaries. I have seen many teams facing this issue in production.

  2. You have to maintain a configuration file to keep the different API key and secret pairs for each environment —eg Dev , QA, Prod.

The preferred way is to use a variable that Quantum exposes solely for this purpose. The variable's name is KNYMobileFabric . You can this like so:

var client = KNYMobileFabric;
client.getIntegrationService(...)

Note: You have to be logged into your Cloud Account in the Visualizer IDE when you build the application in order for the service definition to be fetched. Associate the application to it's Fabric counterpart by using the "MobileFabric " menu item on left hand side. The dropdown will have an option called "Link Application"

More detailed examples are found in the docs:

http://docs.kony.com/konylibrary/konyfabric/kony_fabric_user_guide/Content/KonyStudio/Installing_KonyJS_SDK.htm

On top of the answer by @AshishKumar this is all very well documented here:

http://docs.kony.com/7_x_PDFs/mobilefabric/kony_docsets/kony/kony-sdk.doc/kony.sdk.html

And contrary to what @highhope says in his answer, there are clear advantages to a manual initialization as well. Code completion for instance works very well with manual initialization, but not at all with the KNYMobileFabric . Also, even if you do use the KNYMobileFabric approach, the keys to all your environments still get hardcoded in the mBaas.properties file. And finally, you can keep your app's key and secret constant over time when you publish newer versions of your Fabric app, so this is not a problem either.

Update:

The updated v9.x docs can be found here .

The initialisation mechanism has evolved and there's no longer an mBaas.properties file.

Also, Fabric now allows you to configure things like the key and secret during publication of your middleware integrations, so that if you choose to hardcode them, you can keep them constant over time.

All this being said, the currently recommended mechanism is to allow the SDK to fetch the key and secret at build-time so it can initialise itself for you. You can then get the initialised instance of the SDK by using the getCurrentInstance or the getDefaultInstance functions.

I generally do this by creating a RequireJS module called getSdk.js —I normally place that in an App Group (a folder, in Visualizer terminology) called util , modules/require/util/getSdk.js .

define(function () {
    function getSdk(){
        var sdk = kony.sdk.getCurrentInstance() || kony.sdk.getDefaultInstance()
        if(sdk === null || typeof sdk === "undefined" || !sdk){
            throw new Error(
                "Error: Null Kony SDK. There's no current or default kony.sdk instance."
            )
        }
        return sdk
    }
    return getSdk
})

I then require that in my controllers or other modules like so:

define(["util/getSdk"], function (getSdk) {
    getSdk().getIntegrationService(...)
})

Note: the legacy variable KNYMobileFabric is a global meant as a shorthand and simple way to get the SDK's default instance. I don't particularly like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM