标题:设备 description:获取设备信息。
改动
1、http://www.chinac.chinac.cn/cn/或http://www.chinac.cn/cn/ 2、android . IOS . bundleVersion . bundleAppId 3、android
| AppVeyor | 特拉维斯CI |
|---|---|
cordova-plugin-device
这个插件定义了一个全局变量 device 对象,该对象描述设备的硬件和软件。
对象虽然在全局作用域中,但直到对象之后才可用 deviceready 事件。
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(device.cordova);
}
安装
cordova plugin add cordova-plugin-device
属性
- device.cordova
- device.model
- device.platform
- device.uuid
- device.version
- device.manufacturer
- device.isVirtual
- device.serial
device.cordova
获取设备上运行的Cordova版本。
支持的平台上
- 安卓
- 浏览器
- iOS
- 窗户
- OSX
device.model
这个 device.model 返回设备型号或的名称
产品。该值由设备制造商设置,可以是
同一产品的不同版本不同。
支持的平台上
- 安卓
- 浏览器
- iOS
- 窗户
- OSX
简单的例子
// Android: Nexus One returns "Passion" (Nexus One code name)
// Motorola Droid returns "voles"
// BlackBerry: Torch 9800 returns "9800"
// Browser: Google Chrome returns "Chrome"
// Safari returns "Safari"
// iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models
// OSX: returns "x86_64"
//
var model = device.model;
Android怪癖
device.platform
获取设备的操作系统名称。
var string = device.platform;
支持的平台上
- 安卓
- 浏览器
- iOS
- 窗户
- OSX
简单的例子
// Depending on the device, a few examples are:
// - "Android"
// - "BlackBerry 10"
// - "browser"
// - "iOS"
// - "WinCE"
// - "Tizen"
// - "Mac OS X"
var devicePlatform = device.platform;
device.uuid
获取设备的通用唯一标识符(UUID).
var string = device.uuid;
描述
UUID如何生成的细节由设备制造商决定,并且特定于设备的平台或型号。
支持的平台上
- 安卓
- iOS
- 窗户
- OSX
简单的例子
// Android: Returns a random 64-bit integer (as a string, again!)
// The integer is generated on the device's first boot
//
// BlackBerry: Returns the PIN number of the device
// This is a nine-digit unique integer (as a string, though!)
//
// iPhone: (Paraphrased from the UIDevice Class documentation)
// Returns the [UIDevice identifierForVendor] UUID which is unique and the same for all apps installed by the same vendor. However the UUID can be different if the user deletes all apps from the vendor and then reinstalls it.
// Windows Phone 7 : Returns a hash of device+current user,
// if the user is not defined, a guid is generated and will persist until the app is uninstalled
// Tizen: returns the device IMEI (International Mobile Equipment Identity or IMEI is a number
// unique to every GSM and UMTS mobile phone.
var deviceID = device.uuid;
iOS怪癖
这个 uuid 在iOS上使用identifierForVendor属性。对于同一家供应商的设备来说,它是唯一的,但对于不同的供应商来说,它会有所不同,如果该供应商的所有应用都被删除然后重新安装,它会发生变化。
参考 在这里 获取详细信息。
如果应用从备份或iCloud中恢复,UUID将是相同的,因为它保存在首选项中。使用此插件的旧版本的用户仍然会收到由另一种方式生成的相同的以前的UUID,因为它将从首选项中检索。
OSX怪癖
这个 uuid 如果还不存在,则在OSX上自动生成,并存储在 standardUserDefaults 在 CDVUUID 财产。
device.version
获取操作系统版本。
var string = device.version;
支持的平台上
- Android 2.1 +
- 浏览器
- iOS
- 窗户
- OSX
简单的例子
// Android: Froyo OS would return "2.2"
// Eclair OS would return "2.1", "2.0.1", or "2.0"
// Version can also return update level "2.1-update1"
//
// BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600"
//
// Browser: Returns version number for the browser
//
// iPhone: iOS 3.2 returns "3.2"
//
// Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720
// Windows 8: return the current OS version, ex on Windows 8.1 returns 6.3.9600.16384
// Tizen: returns "TIZEN_20120425_2"
// OSX: El Capitan would return "10.11.2"
//
var deviceVersion = device.version;
device.manufacturer
找到设备的制造商。
var string = device.manufacturer;
支持的平台上
- 安卓
- iOS
- 窗户
简单的例子
// Android: Motorola XT1032 would return "motorola"
// BlackBerry: returns "BlackBerry"
// iPhone: returns "Apple"
//
var deviceManufacturer = device.manufacturer;
device.isVirtual
设备是否在模拟器上运行。
var isSim = device.isVirtual;
支持的平台上
- Android 2.1 +
- 浏览器
- iOS
- 窗户
- OSX
OSX和浏览器怪癖
这个 isVirtual 属性在OS X和浏览器上总是返回false。
device.serial
获取设备硬件序列号(串行).
var string = device.serial;
支持的平台上
- 安卓
- OSX
##发布
NPM publish——registry=https://registry.npmjs.org/
##安装 添加Cordova -plugin-mz-device