ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

ionicPlatform doesn't help you determine if using ionic serve

Open cfjedimaster opened this issue 11 years ago • 17 comments

When using Ionic Serve, you will get a class added to your BODY (http://ionicframework.com/docs/api/utility/ionic.Platform/) that reports if you are using the browser (platform-browser). However, there is no such corresponding support for ionic.Platform (http://ionicframework.com/docs/api/utility/ionic.Platform/). Now - I tend to think adding code for the browser means you are wasting a bit of space in your production code, but it seems like if you support it in one place you should support it here too.

cfjedimaster avatar Sep 01 '15 18:09 cfjedimaster

Ok, so you can check using ionic.Platform.platforms. Does it make sense to add a isBrowser method? I think maybe so. If you don't agree, just close, I won't be offended. ;)

cfjedimaster avatar Sep 01 '15 19:09 cfjedimaster

you can check one of the following to detect that your on the browser (serve)

ionic.Platform.isWebView();
ionic.Platform.is('browser');

djett41 avatar Sep 05 '15 17:09 djett41

According to the docs, isWebView is: "Check if we are running within a WebView (such as Cordova)"

That to me is not the the same as the browser. Let me see if it works.

cfjedimaster avatar Sep 07 '15 03:09 cfjedimaster

Also, ionic.Platform.is is not documented.

cfjedimaster avatar Sep 07 '15 03:09 cfjedimaster

So yeah - I tested, it returns false in the browser, as expected by the docs.

cfjedimaster avatar Sep 07 '15 03:09 cfjedimaster

isWebView is referring to the native webview cordova runs in, which is about the same as just checking for !!window.cordova which will only be available on device when cordova is run. Will always be false in browser and true on device

djett41 avatar Sep 07 '15 03:09 djett41

Then I'm confused as to why you suggested it. :)

cfjedimaster avatar Sep 07 '15 03:09 cfjedimaster

maybe im not understanding what youre asking for... you want your app to know whether or not you are running on broswer such as chrome for testing (ionic serve) or whether or not your running on actual device correct?

If thats true, then what I suggested will be good for what you want, its quite simple either cordova will be available (on device) or it wont (on browser). So ionic gives you a few utility methods as I suggested to give you that information.

ionic.Platform.isWebView() (will be false in ionic serve, true on device)
!!window.cordova (same as above if you are just using cordova rther than phonegap)
ionic.Platform.is('browser') (will be true in ionic serve, false on device)

djett41 avatar Sep 07 '15 04:09 djett41

Ah - ok - you meant check for !isWebView. Heh, ok, that makes sense. I still think a isBrowser() would make sense too.

Also, is('browser') isn't documented, so if it is valid, then it needs to be. I'll add a bug report for it.

cfjedimaster avatar Sep 07 '15 04:09 cfjedimaster

I am getting "false" for the above ionic.Platform.is('browser') and "macintel" rather than "browser" for "ionic.Platform.platform()". Is there a way to get just generic "browser" as mentioned above? ...to Clarify, a way that is not semantically confusing such as !isWebView = "this is a browser".

carbondesign avatar Feb 07 '16 13:02 carbondesign

Thanks for opening an issue with us! Since this is more of a question you will be able to get a better answer over at our forum (https://forum.ionicframework.com/) or our slack channel (http://ionicworldwide.herokuapp.com/). Thanks again!

jgw96 avatar Mar 15 '16 16:03 jgw96

Does it make sense that on my real android app ionic.Platform.isWebView() returns false? I've still found no good way to know when i'm running in a browser (whether on a desktop OR a mobile browser) and when i'm truly an 'app' (IOS or Android). Is there a full-proof way yet?

jeffthompson1971 avatar May 30 '16 00:05 jeffthompson1971

Same as jeffthompson1971. ionic.Platform.isWebView() returns false in my android device

CarlosRoig avatar Jun 03 '16 07:06 CarlosRoig

API is updated http://ionicframework.com/docs/v2/api/platform/Platform/

mehdhi avatar Jun 16 '16 08:06 mehdhi

So now you inject it and call

this.platform.is('mobileweb') || this.platform.is('core') to detect whether or not it's running on a laptop or desktop machine via a web browser.

kamok avatar Feb 02 '17 20:02 kamok

Open app in device's Chrome browser does not set this.platform.is('mobileweb') to true. I need cordova for the browser too, not just in android or ios. For now it seems I can use platform.url() and see if it starts with 'file://'. But it doesn't feel right.

dkrahn avatar Sep 18 '17 11:09 dkrahn

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 02 '18 02:09 ionitron-bot[bot]