I'm creating an omni-channel application using Kony and though it's all a single Javascript codebase, I'd like to conditionally execute some logic depending on whether the app is running on iOS, Android or a web browser. Something like:
if(isAndroid()) {
//Do some stuff specific to Android.
}
else if(isIos()) {
//Do some stuff specific to iOS.
}
else if(isWeb()) {
//Do some stuff specific to Web.
}
Kony supports Preprocessor Directives such as
#ifdefmuch like the C compiler's preprocessors. Since Kony projects are written in Javascript, these statements must be added in the form of special comments in order not to break the Javascript syntax. So for example#ifdefbecomes//#ifdef.These directives can be used to write code which gets built into the application or not depending on the host OS. So I've solved this by writing this:
And then writing the rest of my logic based on the value of my
channelvariable.For a full list of the macros defined which you can use in these
//#ifdefstatements you can look at the first few lines in thekony_sdk.jsmodule created by default in every Kony Visualizer project.