如何在离子中查找设备操作系统和版本 [英] How to find device os and version in ionic
本文介绍了如何在离子中查找设备操作系统和版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了一些教程,最后在离子框架中找到了一些关于此的内容.....
I have worked on few tutorials and at last found something regarding this in ionic framework.....
他们提供了一些使用 ionic native 的代码,我通过嵌入以下代码来做到这一点:
They gave some codes that use ionic native and i did the same by embedding the below code:
//Display OS name and version (Start)
import { Device } from 'ionic-native';
console.log('Device OS is: ' + Device.device.platform);
console.log('Device OS Version is: ' + Device.device.version);
//Display OS name and version (End)
在使用 ionic serve 时,我在控制台中得到了这个:
While using ionic serve i got this in the console:
'Device OS is: undefined'
'Device OS version is: undefined'
然后我猜它在浏览器中不起作用,我尝试在我的手机中构建和运行,但仍然出现相同的日志......
Then i guessed it wont work in browser and i tried building and run in my phone but still the same log comes...
PS:我刚开始接触离子
PS: I have just started with ionic
先谢谢你:)
推荐答案
请查看此链接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
});
这篇关于如何在离子中查找设备操作系统和版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文