node.js - 识别是否部署在移动应用程序或 Web 应用程序上的环境变量?
问题描述
嗨,我正在使用带有 Angular 的 Ionic 5。我有一个移动应用程序,我目前正在为其开发一个 Web 应用程序,它使用与移动应用程序相同的代码库。
我正在寻找一种方法来配置一些环境变量以识别应用程序是部署在移动应用程序还是 Web 应用程序上。谢谢 :)
解决方案
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!");
}
});
}
}
推荐阅读
- django - get_absolute_url 创建空白链接
- node.js - 某些应用程序的 pm2 计划重新加载
- java - 使用 Java 流从员工列表中获取特定日期之前和之后的员工
- python-3.x - 从 many2many 向导(或)TransientModel 在 Many2one 字段中创建值
- php - PHP Curl 发布并获得响应
- c++ - 带有自定义重采样变换过滤器的 Directshow
- python - Python 中的函数将列表视为全局变量。如何解决这个问题?
- css - 在图像周围环绕背景填充
- react-native - 为什么在 React-Native 中使用 Drawer-Navigator 导航到另一个 Navigator 后出现空白屏幕?
- odoo - 在行中添加删除选项,就像我们在购物车中一样