How to find device os and version in ionic

后端 未结 4 400
半阙折子戏
半阙折子戏 2021-01-24 09:27

I have worked on few tutorials and at last found something regarding this in ionic framework.....

They gave some codes that use ionic native and i did the same by embedd

相关标签:
4条回答
  • 2021-01-24 09:47

    I used cordova-plugin-device to fetch uuid number and device model name. It fetches all possible information about the device. I believe, It will also serve your purpose. Inside onDeviceReady() function, you just assign the values to your convenient variables, like: var deviceOS = device.uuid; var deviceVersion = device.version; Hope It helps. Please let me know if it works. :)

    0 讨论(0)
  • 2021-01-24 09:58

    Please see this link http://ionicframework.com/docs/api/utility/ionic.Platform/

    angular.module('PlatformApp', ['ionic'])
    .controller('PlatformCtrl', function($scope) {
    
      ionic.Platform.ready(function(){
        // will execute when device is ready, or immediately if the device is already ready.
      });
    
      var deviceInformation = ionic.Platform.device();
    
      var isWebView = ionic.Platform.isWebView();
      var isIPad = ionic.Platform.isIPad();
      var isIOS = ionic.Platform.isIOS();
      var isAndroid = ionic.Platform.isAndroid();
      var isWindowsPhone = ionic.Platform.isWindowsPhone();
    
      var currentPlatform = ionic.Platform.platform();
      var currentPlatformVersion = ionic.Platform.version();
    
      ionic.Platform.exitApp(); // stops the app
    });
    
    0 讨论(0)
  • 2021-01-24 10:02

    You can get the device os and version in ionic

    import { Device } from '@ionic-native/device';
    import { Platform } from 'ionic-angular';
    
    constructor(private device: Device,public platform: Platform) { 
    
       console.log('Device UUID is: ' + this.device.uuid);
    
       if (this.platform.is('ios')) {
        // This will only print when on iOS
         console.log('I am an iOS device!');
       }
       if (this.platform.is('android')) {
        // This will only print when on Android
         console.log('I am an android device!');
       }
    }
    
    0 讨论(0)
  • 2021-01-24 10:06

    In Ionic 3 you can use device this way,

    import { Device } from '@ionic-native/device';
    
    private platformType:any;
    private versionType:any;
    
    constructor(private device: Device) { 
    this.platformType = this.device.platform;
    this.versionType = this.device.version;
    }
    

    Now this can be used in the html file using data-binding ex:

    <ion-grid>
      <ion-row>
       <ion-col>
         <h1>Platform Type: {{platformType}}</h1>
       </ion-col>
      </ion-row>
      <ion-row>
       <ion-col>
        <h1>OS Version: {{versionType}}</h1>
       </ion-col>
      </ion-row>
    </ion-grid>
    

    Note: In the browser the variables will log null. The Device plugin function will only work on the native devices. You can test your device with

    ionic cordova run (android or ios) --device
    
    0 讨论(0)
提交回复
热议问题