I find out that is hard to know correctly what platform am I running on.
I want to detect if the app is running on web brower or through a native app.
this.platform.is doesn’t work. I thought using
this.platform.is('desktop') would work but not at all.
So I used a trick
!document.URL.startsWith('http') || document.URL.startsWith('http://localhost:8080') which also doesn’t work on some cases.
Like on Android.
Does someone know a working and proper way to detect what platform, web or native am I using ?
EDIT: Using on iOS
console.log(this.platform.platforms()) I got the same output with the native app and the browser. Same for android app/browser.
Any help would be nice
Can you describe in concrete terms what you intend to do with this information? The reason I ask is that oftentimes people use things like “web or native” as a proxy for much more granular concerns like “can I store data quasi-permanently so that it’s available even when offline?” or “do I present a touchscreen-optimized interface?”.
I would advise you to check for the most precise, narrowly tailored feature (or lack thereof) you can, even if that means doing what seem at first blush to be multiple redundant checks. Even if it’s true today that “web or native” is a meaningful and reliable indicator of whether you can or can’t X, it may very well not be true tomorrow, and it would be annoying if you had to rearchitect your app every time that changes.
It’s for multiple reasons… To display proper tutorial pages, regarding it’s the native app or the web browser. To ask cookie consent only on browsers, and I guess other features in future.