| 15747 |
anikendra |
1 |
<!---
|
|
|
2 |
Licensed to the Apache Software Foundation (ASF) under one
|
|
|
3 |
or more contributor license agreements. See the NOTICE file
|
|
|
4 |
distributed with this work for additional information
|
|
|
5 |
regarding copyright ownership. The ASF licenses this file
|
|
|
6 |
to you under the Apache License, Version 2.0 (the
|
|
|
7 |
"License"); you may not use this file except in compliance
|
|
|
8 |
with the License. You may obtain a copy of the License at
|
|
|
9 |
|
|
|
10 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
11 |
|
|
|
12 |
Unless required by applicable law or agreed to in writing,
|
|
|
13 |
software distributed under the License is distributed on an
|
|
|
14 |
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
15 |
KIND, either express or implied. See the License for the
|
|
|
16 |
specific language governing permissions and limitations
|
|
|
17 |
under the License.
|
|
|
18 |
-->
|
|
|
19 |
|
|
|
20 |
# org.apache.cordova.device
|
|
|
21 |
|
|
|
22 |
這個外掛程式定義全球 `device` 物件,描述該設備的硬體和軟體。 雖然物件是在全球範圍內,但不是可用,直到後 `deviceready` 事件。
|
|
|
23 |
|
|
|
24 |
document.addEventListener("deviceready", onDeviceReady, false);
|
|
|
25 |
function onDeviceReady() {
|
|
|
26 |
console.log(device.cordova);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
## 安裝
|
|
|
31 |
|
|
|
32 |
cordova plugin add org.apache.cordova.device
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
## 屬性
|
|
|
36 |
|
|
|
37 |
* device.cordova
|
|
|
38 |
* device.model
|
|
|
39 |
* device.platform
|
|
|
40 |
* device.uuid
|
|
|
41 |
* device.version
|
|
|
42 |
|
|
|
43 |
## device.cordova
|
|
|
44 |
|
|
|
45 |
獲取科爾多瓦在設備上運行的版本。
|
|
|
46 |
|
|
|
47 |
### 支援的平臺
|
|
|
48 |
|
|
|
49 |
* 亞馬遜火 OS
|
|
|
50 |
* Android 系統
|
|
|
51 |
* 黑莓 10
|
|
|
52 |
* 瀏覽器
|
|
|
53 |
* 火狐瀏覽器的作業系統
|
|
|
54 |
* iOS
|
|
|
55 |
* 泰
|
|
|
56 |
* Windows Phone 7 和 8
|
|
|
57 |
* Windows 8
|
|
|
58 |
|
|
|
59 |
## device.model
|
|
|
60 |
|
|
|
61 |
`device.model`返回設備的模型或產品的名稱。值由設備製造商設置和同一產品的不同版本可能不同。
|
|
|
62 |
|
|
|
63 |
### 支援的平臺
|
|
|
64 |
|
|
|
65 |
* Android 系統
|
|
|
66 |
* 黑莓 10
|
|
|
67 |
* 瀏覽器
|
|
|
68 |
* iOS
|
|
|
69 |
* 泰
|
|
|
70 |
* Windows Phone 7 和 8
|
|
|
71 |
* Windows 8
|
|
|
72 |
|
|
|
73 |
### 快速的示例
|
|
|
74 |
|
|
|
75 |
// Android: Nexus One returns "Passion" (Nexus One code name)
|
|
|
76 |
// Motorola Droid returns "voles"
|
|
|
77 |
// BlackBerry: Torch 9800 returns "9800"
|
|
|
78 |
// Browser: Google Chrome returns "Chrome"
|
|
|
79 |
// Safari returns "Safari"
|
|
|
80 |
// iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. 請參閱 HTTP://theiphonewiki.com/wiki/index.php?title=Models / / var 模型 = device.model ;
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
### Android 的怪癖
|
|
|
84 |
|
|
|
85 |
* 獲取[產品名稱][1]而不是[產品型號名稱][2],這往往是生產代碼名稱。 例如,Nexus One 返回 `Passion` ,和摩托羅拉 Droid 返回`voles`.
|
|
|
86 |
|
|
|
87 |
[1]: http://developer.android.com/reference/android/os/Build.html#PRODUCT
|
|
|
88 |
[2]: http://developer.android.com/reference/android/os/Build.html#MODEL
|
|
|
89 |
|
|
|
90 |
### Tizen 怪癖
|
|
|
91 |
|
|
|
92 |
* 例如,返回與供應商指派的設備模型`TIZEN`
|
|
|
93 |
|
|
|
94 |
### Windows Phone 7 和 8 怪癖
|
|
|
95 |
|
|
|
96 |
* 返回由製造商指定的設備模型。例如,三星焦點返回`SGH-i917`.
|
|
|
97 |
|
|
|
98 |
## device.platform
|
|
|
99 |
|
|
|
100 |
獲取設備的作業系統名稱。
|
|
|
101 |
|
|
|
102 |
var string = device.platform;
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
### 支援的平臺
|
|
|
106 |
|
|
|
107 |
* Android 系統
|
|
|
108 |
* 黑莓 10
|
|
|
109 |
* Browser4
|
|
|
110 |
* 火狐瀏覽器的作業系統
|
|
|
111 |
* iOS
|
|
|
112 |
* 泰
|
|
|
113 |
* Windows Phone 7 和 8
|
|
|
114 |
* Windows 8
|
|
|
115 |
|
|
|
116 |
### 快速的示例
|
|
|
117 |
|
|
|
118 |
// Depending on the device, a few examples are:
|
|
|
119 |
// - "Android"
|
|
|
120 |
// - "BlackBerry 10"
|
|
|
121 |
// - Browser: returns "MacIntel" on Mac
|
|
|
122 |
// returns "Win32" on Windows
|
|
|
123 |
// - "iOS"
|
|
|
124 |
// - "WinCE"
|
|
|
125 |
// - "Tizen"
|
|
|
126 |
var devicePlatform = device.platform;
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
### Windows Phone 7 的怪癖
|
|
|
130 |
|
|
|
131 |
Windows Phone 7 設備報告作為平臺`WinCE`.
|
|
|
132 |
|
|
|
133 |
### Windows Phone 8 怪癖
|
|
|
134 |
|
|
|
135 |
Windows Phone 8 設備報告作為平臺`Win32NT`.
|
|
|
136 |
|
|
|
137 |
## device.uuid
|
|
|
138 |
|
|
|
139 |
獲取設備的通用唯一識別碼 ([UUID][3]).
|
|
|
140 |
|
|
|
141 |
[3]: http://en.wikipedia.org/wiki/Universally_Unique_Identifier
|
|
|
142 |
|
|
|
143 |
var string = device.uuid;
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
### 說明
|
|
|
147 |
|
|
|
148 |
如何生成一個 UUID 的細節由設備製造商和特定于設備的平臺或模型。
|
|
|
149 |
|
|
|
150 |
### 支援的平臺
|
|
|
151 |
|
|
|
152 |
* Android 系統
|
|
|
153 |
* 黑莓 10
|
|
|
154 |
* iOS
|
|
|
155 |
* Tizen
|
|
|
156 |
* Windows Phone 7 和 8
|
|
|
157 |
* Windows 8
|
|
|
158 |
|
|
|
159 |
### 快速的示例
|
|
|
160 |
|
|
|
161 |
/ / Android: 一個隨機的 64 位整數 (作為字串返回,再次!) / / 上設備的第一次啟動生成的整數 / / / / 黑莓手機: 返回設備的 PIN 號碼 / / 這是九個數字的唯一整數 (作為字串,雖然!) / / / / iPhone: (從 UIDevice 類文檔解釋) / / 返回一個字串的雜湊值創建的多個硬體標識。
|
|
|
162 |
/ / 它保證是唯一的每個設備並不能綁 / / 到使用者帳戶。
|
|
|
163 |
/ / Windows Phone 7: 返回的雜湊代碼的設備 + 當前使用者,/ / 如果未定義使用者,則一個 guid 生成的並且將會保留直到卸載該應用程式 / / Tizen: 返回設備 IMEI (國際行動裝置身份或 IMEI 是一個數位 / / 獨有的每一個 UMTS 和 GSM 行動電話。
|
|
|
164 |
var deviceID = device.uuid;
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
### iOS 怪癖
|
|
|
168 |
|
|
|
169 |
`uuid`在 iOS 不是唯一的一種裝置,但對於每個應用程式,為每個安裝而異。 如果您刪除並重新安裝該應用程式,它更改和可能還當你升級 iOS,或甚至升級每個版本 (iOS 5.1 中存在明顯的) 的應用程式。 `uuid`不是一個可靠的值。
|
|
|
170 |
|
|
|
171 |
### Windows Phone 7 和 8 怪癖
|
|
|
172 |
|
|
|
173 |
`uuid`為 Windows Phone 7 須經許可 `ID_CAP_IDENTITY_DEVICE` 。 Microsoft 可能會很快棄用此屬性。 如果沒有可用的能力,應用程式將生成設備上應用程式的安裝過程中保持持續的 guid。
|
|
|
174 |
|
|
|
175 |
## device.version
|
|
|
176 |
|
|
|
177 |
獲取作業系統版本。
|
|
|
178 |
|
|
|
179 |
var string = device.version;
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
### 支援的平臺
|
|
|
183 |
|
|
|
184 |
* Android 2.1 +
|
|
|
185 |
* 黑莓 10
|
|
|
186 |
* 瀏覽器
|
|
|
187 |
* iOS
|
|
|
188 |
* 泰
|
|
|
189 |
* Windows Phone 7 和 8
|
|
|
190 |
* Windows 8
|
|
|
191 |
|
|
|
192 |
### 快速的示例
|
|
|
193 |
|
|
|
194 |
// Android: Froyo OS would return "2.2"
|
|
|
195 |
// Eclair OS would return "2.1", "2.0.1", or "2.0"
|
|
|
196 |
// Version can also return update level "2.1-update1"
|
|
|
197 |
//
|
|
|
198 |
// BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600"
|
|
|
199 |
//
|
|
|
200 |
// Browser: Returns version number for the browser
|
|
|
201 |
//
|
|
|
202 |
// iPhone: iOS 3.2 returns "3.2"
|
|
|
203 |
//
|
|
|
204 |
// Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720
|
|
|
205 |
// Tizen: returns "TIZEN_20120425_2"
|
|
|
206 |
var deviceVersion = device.version;
|