Detecting Environment

3 posts, 0 answers
  1. Peter
    Peter avatar
    1 posts
    Member since:
    Mar 2015

    Posted 27 Apr 2015 Link to this post

    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. Mark
    Mark avatar
    9 posts
    Member since:
    Sep 2014

    Posted 28 Apr 2015 in reply to Peter Link to this post

    I use this mechanism for environment specific configurations:

     

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

  3. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 30 Apr 2015 Link to this post

    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.

     
Back to Top