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.
<
Ionic 4 / Capacitor
I have written a service like so:
detect-platform.service.ts
import { Injectable } from '@angular/core';
import { Platform } from '@ionic/angular';
import { find } from 'lodash';
@Injectable({
providedIn: 'root'
})
export class DetectPlatformService {
isDevice: boolean = false;
constructor(
private platform: Platform, ) { }
setPlatform(): void {
const platforms: string[] = this.platform.platforms();
const platform: string = find(platforms, (p: string) => {
return p === 'capacitor';
});
this.isDevice = platform ? true : false;
}
}
Note: Since I use Ionic 4/Capacitor
it gives true
if it is on device
else false
.