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

Detect if in simulator

6 Answers 204 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.
Ned
Top achievements
Rank 1
Ned asked on 03 Nov 2014, 02:16 PM
So, I used to use if (window.device.name) to check if I was in a simulator or a native device. But, you guys are now passing all of the device info so the simulator thinks it's a real device! Nice. So, is there another way to check if I'm on a device or in the simulator? I need this to handle not loading some plugins that error out when on the simulator (AdMob etc). Thanks!

6 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 03 Nov 2014, 02:47 PM
Hello Ned,

You can use the following code to check if your app is running in the device simulator:
checkSimulator: function() {
    if (window.navigator.simulator === true) {
        alert('This plugin is not available in the simulator.');
        return true;
    } else if (window.plugins === undefined || window.plugins.AdMob === undefined) {
        alert('Plugin not found. Maybe you are running in AppBuilder Companion app which currently does not support this plugin.');
        return true;
    } else {
        return false;
    }
}

Let me know if that helps.

Regards,
Tina Stancheva
Telerik
 

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

 
0
Ned
Top achievements
Rank 1
answered on 03 Nov 2014, 05:40 PM
Hmm, simulator is not defined. I'm using appbuilder-cli on osx.
0
Tina Stancheva
Telerik team
answered on 04 Nov 2014, 11:29 AM
Hi Ned,

The simulator property is something we add dynamically when you run your project in the simulator. This is why if the app is running outside the AppBuilder device simulator, the property will be undefined.

If, however, the property is undefined when you run the app in your simulator, we will need to examine your app or a sample app where the issue reproduces. Only then we will be able to investigate the cause behind the error.

Regards,
Tina Stancheva
Telerik
 

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

 
0
Kamlesh
Top achievements
Rank 1
answered on 11 Jan 2016, 06:55 AM

Hi Tina,

I'm using telerik app builder and plugin 'Printer-master' from https://github.com/katzer/cordova-plugin-printer

When I check to printer available than, error like : Plugin not found. Maybe you are running in AppBuilder Companion app which currently does not support this plugin.

I can't understand it. please help.

0
Kamlesh
Top achievements
Rank 1
answered on 13 Jan 2016, 10:00 AM

Sorry, I forgot these steps.

Run -> Build -> Android-> App package

After following these, success.

Thanks.

0
Tina Stancheva
Telerik team
answered on 13 Jan 2016, 04:03 PM
Hi Kamlesh,

Currently the AppBuilder companion app and the AppBuilder device simulator don't support custom plugins. I believe this was the cause for the behavior you experienced. You can check the following articles for a complete list of the supported plugins within the companion app and the device simulator:
Let me know if you have more questions.

Regards,
Tina Stancheva
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
Ned
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Ned
Top achievements
Rank 1
Kamlesh
Top achievements
Rank 1
Share this question
or