How to detect platform using Ionic 4

前端 未结 8 1031
慢半拍i
慢半拍i 2021-02-09 08:24

How to detect browser and mobileweb platform using Ionic 4 because when I tried with below code in desktop browser it is not falling in ‘core’ condition.

<
8条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-09 09:00

    Currently Ionic 4 has support for platform detection. The following code works for me.

    import { Platform } from '@ionic/angular';
    ...
    constructor(private platform: Platform) {}
    ...
    ngOnInit() {
       this.platform.ready().then(() => {
          if (this.platform.is('android')) {
               console.log('android');
          } else if (this.platform.is('ios')) {
               console.log('ios');
          } else {
               //fallback to browser APIs or
               console.log('The platform is not supported');
                 }
          }}
    

提交回复
热议问题