How to detect platform using Ionic 4


#1

How to get platform information using Ionic 4.

In Ionic 3 , we can do as mentioned below.

    if(this.platform.is('android') || this.platform.is('ios') || this.platform.is('core'))
    {
    }

But this is not working in Ionic 4. Can anyone please help me how to do this in Ionic 4 or what can be the alternate for this?


#2

Depending on what you want to do:


#3

@Sujan12 How to detect desktop browser platform using this because when I tried with below it is not falling in ‘core’ condition.

      if (this.platform.is('core')) {
        alert('core platform');
      } else {
        alert('something else');
      }

#4

No idea, the link I posted only refers to a is('cordova').


#5

Is there a workaround for this yet?
Detecting ‘core’ or desktop browser in any way other than screen size?


#6

This just got updated yesterday. Looks like ‘core’ is supposed to work. I know it doesn’t now, but maybe in the next update?


#7

I am using

this.isApp = (!document.URL.startsWith(‘http’) || document.URL.startsWith(‘http://localhost:8080’));

So if isApp is true I am running native on Android or IOS else it is in the browser


#8

@btsiders Great, looking forward to it. Thanks for the heads up.
@developergeme Thanks for that too. I’ll try it tomorrow if there is no update.
Cheers


#9

Desktop is now detected in 4.0.0-beta.4


#10

For me it’s still showing android platform while detecting in desktop.

Below is my ionic info :

Ionic:
ionic (Ionic CLI) : 4.1.1 (C:\Users\test\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.0.0-beta.1
@angular-devkit/core : 0.7.2
@angular-devkit/schematics : 0.7.2
@angular/cli : 6.1.2
@ionic/ng-toolkit : 1.0.5
@ionic/schematics-angular : 1.0.4

Cordova:

cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 6.2.3
Cordova Plugins : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 2.0.0, (and 4 other plugins)

System:

Android SDK Tools : 26.1.1 (C:\Users\test\AppData\Local\Android\sdk)
NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)
npm : 5.6.0
OS : Windows 10


#11

Your are still using beta.1.


#12

Here is a post with some upgrade instructions;

Note: the current is Beta 5 but the desktop detection came in beta 4.


#13

Thanks for upgrade instructions.


#14

On Ionic 4 Platform is unber ‘@ionic/angular’

import { Platform } from ‘@ionic/angular’;