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.
if (this.platform.is('core')) {
alert('core platform');
} else {
alert('something else');
}
When I have debug in chrome developer tool it showing 'android' platform as per below snapshot.
Can anyone please help me how to detect platform in Ionic 4 or what can be the alternative for this?
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');
}
}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With