Check if "ion feed" is working to use the legend in the program

Is there a way to detect that the ionic serve CLI works (and then not on a real device) in the program and uses it as a conditional.

My problem: I have a Cordova plugin that sends a response to Cordoba.

When I used Ripple, he suggested choosing a callback value to send back to JavaScript (to emulate the result of the plugin).

I notice that Ionic2 does not do this when I launch the browser. Therefore, in order to facilitate the work of my developer and to give the opportunity to test it in a browser (and not build on a real device all the time), I would like to be able to check the program if the CLI ionic serve works. In other words: check if it works on a real device or in a regular browser .

If it works in a browser, I used a hint to ask the user to enter a dummy value for the result of the Cordova plugin instead of the real Cordova plugin.

+8
angular cordova typescript ionic2 ionic3
source share
1 answer

See Platform doc:

Check if it works on a real device or in a regular browser.

You can use platform information to do this:

 Platform Name Description android on a device running Android. cordova on a device running Cordova. core on a desktop device. ios on a device running iOS. ipad on an iPad device. iphone on an iPhone device. mobile on a mobile device. mobileweb in a browser on a mobile device. phablet on a phablet device. tablet on a tablet device. windows on a device running Windows. 

So you can do something like this:

 import { Platform } from 'ionic-angular'; @Component({...}) export MyPage { constructor(public platform: Platform) { if (this.platform.is('mobileweb') || this.platform.is('core')) { // This will only print when running on desktop console.log("I'm a regular browser!"); } } } 
+11
source share

All Articles