Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Create Simulator-Related Logic

During development, you can create simulator-only logic in your apps to work around some of the limitations of the device simulator or to control your local test environment. For example, when your app is running in the simulator, you might show or log warnings when you try to call methods of unsupported plugins or you can point your app to consume resources from an alternative location.


Simulator JavaScript API

AppBuilder provides the boolean window.navigator.simulator custom property. This property has the following values.

  • true: Indicates that the app is running in the simulator.
  • false: Indicates that the app is not running in the simulator.

Simulator JavaScript API Examples

Click the JavaScript tabs to switch between the examples.

/* 
* Detects if the app is running in the simulator.
* If running in the simulator, shows a simple warning alert.
* When the alert is dismissed, executes the logic defined in dismissAlert.
*/

if (window.navigator.simulator === true) {
    navigator.notification.alert("Your app is running in the device simulator. Test results might be inaccurate.", dismissAlert, "Simulator Alert", "OK");  
};
/*
* Detects if the app is running in the simulator.
* If running in the simulator, prints a warning in the console.
* Continues executing the logic of your app.
*/

if (window.navigator.simulator === true) {
    console.log("Your app is running in the device simulator. Test results might be inaccurate.")  
};
/*
* Sets a configuration based on whether the app is running in the simulator.
*/

function setConfig() {
  if (window.navigator.simulator === true) {
     apiUrl = "http://localhost:1234/api/myapp";
     }
  else {
     apiUrl = "https://myapp.com/api/myapp";
    }
};

Best Practice

You might want to check if your app is running in the device simulator in your onDeviceReady callback and implement your simulator-related logic there. This way, as soon as Apache Cordova has fully loaded and right before executing any other code, you can apply your simulator-related logic. For example, you can make configuration changes which affect the behavior and performance of your app.

Next Steps

Launch the simulator.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.