How to detect if I am in browser (local development) in Ionic 2

前端 未结 7 1244
太阳男子
太阳男子 2020-12-03 03:00

I want to make sure to launch inappbrowser only if I am on devices (iOs, Android...), but if I am in browser (local development mode or just a Web App with gulp build), I wa

7条回答
  •  天涯浪人
    2020-12-03 03:25

    The most reliable solution for me was a combination of at Platform's .is() method and its promise result. I used the check inside a provider, so I could use it globally. Maybe the approach is useful to someone who has exhausted the other paths.

    import { Platform } from 'ionic-angular';
    
    constructor(public platform: Platform) { 
    
      public env:string = 'dev';
    
      this.platform.ready().then((readySource) => {
    
        if (readySource) {
          if (platform.is('core') || readySource.toLowerCase() !== 'cordova') {
            this.env = 'dev';
          }
          else {
            this.env = 'production';
          }
        }
    

提交回复
热议问题