This is a migrated thread and some comments may be shown as answers.

Detecting Environment

2 Answers 117 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Peter
Top achievements
Rank 1
Peter asked on 27 Apr 2015, 08:26 AM

I'm developing my first mobile app using the Telerik platform and I'm trying to find a way of dynamically setting the configuration based on the environment that the code is running in. e.g.:var apiUrl;

function setConfig()
{
  if (window.navigator.simulator)
  {
    // Debug in simulator
    apiUrl = "http://localhost:1234/api/myapp";
  }
  else if ( ??? )
  {
    // System Testing
    apiUrl = "https://beta.myapp.com/api/myapp";
  }
  else {
    // Production
    apiUrl = "https://myapp.com/api/myapp";
  }
}

What I'd like to be able to do is tell if the application is running within the AppBuilder mobile app, which I'm using for system testing, or as a packaged application (production app)

I've had a trawl through the javascript API, but can't see anything that seems to fit the bill, and I don't expect to find anything in the Cordova API since this is specific to the telerik platform.

 Any ideas?

2 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 28 Apr 2015, 05:57 AM

I use this mechanism for environment specific configurations:

 

http://docs.telerik.com/platform/appbuilder/build-configurations/apply-build-configurations

0
Kaloyan
Telerik team
answered on 30 Apr 2015, 10:58 AM
Hi Peter,

At this stage, the only possible way to check if your application is running in the AppBuilder Companion apps or as an application package is to check if certain custom Cordova plugin is initialized. For example, let's say you have the AdMob plugin in the project. Then, you could have the following check:
function setConfig()
{
  if (window.navigator.simulator)
  {
    // Debug in simulator
    apiUrl = "http://localhost:1234/api/myapp";
  }
  else if (!window.navigator.simulator && typeof window.plugins.AdMob === "undefined")
  {
    // System Testing
  }
  else {
    // Production
    apiUrl = "https://myapp.com/api/myapp";
  }
}


However, the above approach is more a hack than an actual solution, as there are situations in which the plugin won't be initialized even in production environment. That's why I do not recommend it. Still, this is the only possible way I can think of at the moment.

Further, I think that the idea of having a way to distinguish whether the app runs in the AppBuilder Companion apps or it is deployed as an application package is very good. So, i have logged it in our backlog for future implementation. I believe it could be ready for the next official release of AppBuilder.

I hope this helps.

Regards,
Kaloyan
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
General Discussion
Asked by
Peter
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Kaloyan
Telerik team
Share this question
or