【问题标题】:Environment variable to recognise if deployed on Mobile App or Web App?识别是否部署在移动应用程序或 Web 应用程序上的环境变量?
【发布时间】:2021-08-10 04:36:47
【问题描述】:

您好,我正在使用带有 Angular 的 Ionic 5。我有一个移动应用程序,我目前正在为其开发一个 Web 应用程序,它使用与移动应用程序相同的代码库。

我正在寻找一种方法来配置一些环境变量以识别应用程序是部署在移动应用程序还是 Web 应用程序上。谢谢:)

【问题讨论】:

    标签: node.js angularjs ionic-framework ionic5


    【解决方案1】:
    import {Platform } from '@ionic/angular';
    
    @Component({
    templateUrl: 'app.html'
    })
    export class MyApp {
        rootPage = HomePage;
    
        constructor(platform: Platform) {
            platform.ready().then(() => {
    
                if (this.platform.is('android')) {
                    console.log("running on Android device!");
                }
                if (this.platform.is('ios')) {
                    console.log("running on iOS device!");
                }
                if (this.platform.is('mobileweb')) {
                    console.log("running in a browser on mobile!");
                }
    
            });
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      • 2018-05-21
      • 2014-01-15
      • 2018-02-20
      • 2021-09-18
      • 1970-01-01
      • 2019-08-13
      相关资源
      最近更新 更多