@tarojs/taro 3.3.13 → 3.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/package.json +5 -5
  2. package/types/api/ad/index.d.ts +34 -28
  3. package/types/api/alipay/index.d.ts +11 -7
  4. package/types/api/base/debug.d.ts +60 -54
  5. package/types/api/base/env.d.ts +12 -8
  6. package/types/api/base/index.d.ts +87 -83
  7. package/types/api/base/system.d.ts +59 -54
  8. package/types/api/base/update.d.ts +37 -33
  9. package/types/api/base/weapp/app-event.d.ts +147 -131
  10. package/types/api/base/weapp/life-cycle.d.ts +14 -10
  11. package/types/api/canvas/index.d.ts +116 -111
  12. package/types/api/cloud/index.d.ts +99 -94
  13. package/types/api/data-analysis/index.d.ts +68 -64
  14. package/types/api/device/accelerometer.d.ts +57 -50
  15. package/types/api/device/battery.d.ts +19 -15
  16. package/types/api/device/ble.d.ts +241 -228
  17. package/types/api/device/bluetooth.d.ts +207 -194
  18. package/types/api/device/clipboard.d.ts +48 -43
  19. package/types/api/device/compass.d.ts +55 -48
  20. package/types/api/device/contact.d.ts +13 -9
  21. package/types/api/device/gyroscope.d.ts +41 -35
  22. package/types/api/device/iBeacon.d.ts +79 -73
  23. package/types/api/device/motion.d.ts +42 -37
  24. package/types/api/device/network.d.ts +80 -42
  25. package/types/api/device/nfc.d.ts +105 -96
  26. package/types/api/device/performance.d.ts +32 -18
  27. package/types/api/device/phone.d.ts +20 -15
  28. package/types/api/device/scan.d.ts +31 -26
  29. package/types/api/device/screen.d.ts +74 -67
  30. package/types/api/device/vibrate.d.ts +31 -25
  31. package/types/api/device/wifi.d.ts +151 -140
  32. package/types/api/ext/index.d.ts +44 -39
  33. package/types/api/files/index.d.ts +219 -209
  34. package/types/api/framework/index.d.ts +25 -20
  35. package/types/api/location/index.d.ts +140 -136
  36. package/types/api/media/audio.d.ts +135 -127
  37. package/types/api/media/background-audio.d.ts +135 -126
  38. package/types/api/media/camera.d.ts +30 -26
  39. package/types/api/media/editor.d.ts +35 -33
  40. package/types/api/media/image.d.ts +163 -150
  41. package/types/api/media/live.d.ts +88 -82
  42. package/types/api/media/map.d.ts +47 -43
  43. package/types/api/media/recorder.d.ts +90 -84
  44. package/types/api/media/video-processing.d.ts +10 -6
  45. package/types/api/media/video.d.ts +63 -58
  46. package/types/api/network/download.d.ts +40 -30
  47. package/types/api/network/mdns.d.ts +104 -91
  48. package/types/api/network/request.d.ts +83 -79
  49. package/types/api/network/udp.d.ts +20 -16
  50. package/types/api/network/upload.d.ts +66 -56
  51. package/types/api/network/websocket.d.ts +201 -194
  52. package/types/api/open-api/account.d.ts +18 -14
  53. package/types/api/open-api/address.d.ts +27 -23
  54. package/types/api/open-api/authorize.d.ts +30 -26
  55. package/types/api/open-api/card.d.ts +55 -51
  56. package/types/api/open-api/customer-service.d.ts +21 -17
  57. package/types/api/open-api/facial.d.ts +28 -24
  58. package/types/api/open-api/invoice.d.ts +38 -34
  59. package/types/api/open-api/login.d.ts +56 -52
  60. package/types/api/open-api/navigate.d.ts +79 -75
  61. package/types/api/open-api/payment.d.ts +34 -30
  62. package/types/api/open-api/settings.d.ts +49 -45
  63. package/types/api/open-api/soter.d.ts +92 -86
  64. package/types/api/open-api/subscribe-message.d.ts +24 -20
  65. package/types/api/open-api/user-info.d.ts +60 -57
  66. package/types/api/open-api/werun.d.ts +50 -46
  67. package/types/api/route/index.d.ts +122 -118
  68. package/types/api/share/index.d.ts +68 -64
  69. package/types/api/storage/background-fetch.d.ts +40 -35
  70. package/types/api/storage/index.d.ts +267 -262
  71. package/types/api/swan/index.d.ts +47 -42
  72. package/types/api/ui/animation.d.ts +21 -17
  73. package/types/api/ui/background.d.ts +38 -34
  74. package/types/api/ui/custom-component.d.ts +22 -18
  75. package/types/api/ui/fonts.d.ts +26 -21
  76. package/types/api/ui/interaction.d.ts +159 -150
  77. package/types/api/ui/keyboard.d.ts +59 -55
  78. package/types/api/ui/menu.d.ts +10 -6
  79. package/types/api/ui/navigation-bar.d.ts +67 -63
  80. package/types/api/ui/pull-down-refresh.d.ts +33 -29
  81. package/types/api/ui/scroll.d.ts +30 -26
  82. package/types/api/ui/sticky.d.ts +22 -19
  83. package/types/api/ui/tab-bar.d.ts +101 -97
  84. package/types/api/ui/window.d.ts +24 -18
  85. package/types/api/worker/index.d.ts +28 -24
  86. package/types/api/wxml/index.d.ts +42 -38
  87. package/types/compile.d.ts +1 -5
  88. package/types/global.d.ts +392 -0
  89. package/types/index.d.ts +12 -98
  90. package/types/taro.api.d.ts +94 -0
  91. package/types/taro.component.d.ts +10 -57
  92. package/types/taro.config.d.ts +28 -6
  93. package/types/taro.extend.d.ts +50 -75
  94. package/types/taro.hooks.d.ts +68 -67
  95. package/types/taro.lifecycle.d.ts +47 -28
  96. package/types/api/ad/index.ts +0 -6
  97. package/types/api/alipay/index.ts +0 -7
  98. package/types/api/index.d.ts +0 -352
@@ -1,4 +1,6 @@
1
- declare namespace Taro {
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
2
4
  namespace readBLECharacteristicValue {
3
5
  interface Option {
4
6
  /** 蓝牙特征值的 uuid */
@@ -8,42 +10,13 @@ declare namespace Taro {
8
10
  /** 蓝牙特征值对应服务的 uuid */
9
11
  serviceId: string
10
12
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
11
- complete?: (res: General.BluetoothError) => void
13
+ complete?: (res: TaroGeneral.BluetoothError) => void
12
14
  /** 接口调用失败的回调函数 */
13
- fail?: (res: General.BluetoothError) => void
15
+ fail?: (res: TaroGeneral.BluetoothError) => void
14
16
  /** 接口调用成功的回调函数 */
15
- success?: (res: General.BluetoothError) => void
17
+ success?: (res: TaroGeneral.BluetoothError) => void
16
18
  }
17
19
  }
18
- /** 读取低功耗蓝牙设备的特征值的二进制数据值。注意:必须设备的特征值支持 read 才可以成功调用。
19
- *
20
- * **注意**
21
- * - 并行调用多次会存在读失败的可能性。
22
- * - 接口读取到的信息需要在 `onBLECharacteristicValueChange` 方法注册的回调中获取。
23
- * @supported weapp
24
- * @example
25
- * ```tsx
26
- * // 必须在这里的回调才能获取
27
- * Taro.onBLECharacteristicValueChange(function(characteristic) {
28
- * console.log('characteristic value comed:', characteristic)
29
- * })
30
- * Taro.readBLECharacteristicValue({
31
- * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
32
- * deviceId,
33
- * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
34
- * serviceId,
35
- * // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
36
- * characteristicId,
37
- * success: function (res) {
38
- * console.log('readBLECharacteristicValue:', res.errCode)
39
- * }
40
- * })
41
- * ```
42
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.readBLECharacteristicValue.html
43
- */
44
- function readBLECharacteristicValue(
45
- option: readBLECharacteristicValue.Option,
46
- ): Promise<General.BluetoothError>
47
20
 
48
21
  namespace onBLEConnectionStateChange {
49
22
  interface CallbackResult {
@@ -57,21 +30,6 @@ declare namespace Taro {
57
30
  result: CallbackResult,
58
31
  ) => void
59
32
  }
60
- /** 监听低功耗蓝牙连接状态的改变事件。包括开发者主动连接或断开连接,设备丢失,连接异常断开等等
61
- * @supported weapp
62
- * @example
63
- * ```tsx
64
- * Taro.onBLEConnectionStateChange(function (res) {
65
- * // 该方法回调中可以用于处理连接意外断开等异常情况
66
- * console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)
67
- * })
68
- * ```
69
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.onBLEConnectionStateChange.html
70
- */
71
- function onBLEConnectionStateChange(
72
- /** 低功耗蓝牙连接状态的改变事件的回调函数 */
73
- callback: onBLEConnectionStateChange.Callback,
74
- ): void
75
33
 
76
34
  namespace onBLECharacteristicValueChange {
77
35
  /** 低功耗蓝牙设备的特征值变化事件的回调函数 */
@@ -89,34 +47,9 @@ declare namespace Taro {
89
47
  value: ArrayBuffer
90
48
  }
91
49
  }
92
- /** 监听低功耗蓝牙设备的特征值变化事件。必须先启用 `notifyBLECharacteristicValueChange` 接口才能接收到设备推送的 notification。
93
- * @supported weapp
94
- * @example
95
- * ```tsx
96
- * // ArrayBuffer转16进制字符串示例
97
- * function ab2hex(buffer) {
98
- * let hexArr = Array.prototype.map.call(
99
- * new Uint8Array(buffer),
100
- * function(bit) {
101
- * return ('00' + bit.toString(16)).slice(-2)
102
- * }
103
- * )
104
- * return hexArr.join('');
105
- * }
106
- * Taro.onBLECharacteristicValueChange(function (res) {
107
- * console.log(`characteristic ${res.characteristicId} has changed, now is ${res.value}`)
108
- * console.log(ab2hex(res.value))
109
- * })
110
- * ```
111
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.onBLECharacteristicValueChange.html
112
- */
113
- function onBLECharacteristicValueChange(
114
- /** 低功耗蓝牙设备的特征值变化事件的回调函数 */
115
- callback: onBLECharacteristicValueChange.Callback,
116
- ): void
117
50
 
118
51
  namespace notifyBLECharacteristicValueChange {
119
- interface Promised extends General.CallbackResult {
52
+ interface Promised extends TaroGeneral.CallbackResult {
120
53
  /** 成功:ok,错误:详细信息 */
121
54
  errMsg: string
122
55
  }
@@ -130,56 +63,28 @@ declare namespace Taro {
130
63
  /** 是否启用 notify */
131
64
  state: boolean
132
65
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
133
- complete?: (res: General.BluetoothError) => void
66
+ complete?: (res: TaroGeneral.BluetoothError) => void
134
67
  /** 接口调用失败的回调函数 */
135
- fail?: (res: General.BluetoothError) => void
68
+ fail?: (res: TaroGeneral.BluetoothError) => void
136
69
  /** 接口调用成功的回调函数 */
137
- success?: (res: General.BluetoothError) => void
70
+ success?: (res: TaroGeneral.BluetoothError) => void
138
71
  }
139
72
  }
140
- /** 启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。注意:必须设备的特征值支持 notify 或者 indicate 才可以成功调用。
141
- *
142
- * 另外,必须先启用 `notifyBLECharacteristicValueChange` 才能监听到设备 `characteristicValueChange` 事件
143
- *
144
- * **注意**
145
- * - 订阅操作成功后需要设备主动更新特征值的 value,才会触发 Taro.onBLECharacteristicValueChange 回调。
146
- * - 安卓平台上,在调用 `notifyBLECharacteristicValueChange` 成功后立即调用 `writeBLECharacteristicValue` 接口,在部分机型上会发生 10008 系统错误
147
- * @supported weapp
148
- * @example
149
- * ```tsx
150
- * Taro.notifyBLECharacteristicValueChange({
151
- * state: true, // 启用 notify 功能
152
- * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
153
- * deviceId,
154
- * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
155
- * serviceId,
156
- * // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
157
- * characteristicId,
158
- * success: function (res) {
159
- * console.log('notifyBLECharacteristicValueChange success', res.errMsg)
160
- * }
161
- * })
162
- * ```
163
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.notifyBLECharacteristicValueChange.html
164
- */
165
- function notifyBLECharacteristicValueChange(
166
- option: notifyBLECharacteristicValueChange.Option,
167
- ): Promise<notifyBLECharacteristicValueChange.Promised>
168
73
 
169
74
  namespace getBLEDeviceServices {
170
75
  interface Option {
171
76
  /** 蓝牙设备 id */
172
77
  deviceId: string
173
78
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
174
- complete?: (res: General.BluetoothError) => void
79
+ complete?: (res: TaroGeneral.BluetoothError) => void
175
80
  /** 接口调用失败的回调函数 */
176
- fail?: (res: General.BluetoothError) => void
81
+ fail?: (res: TaroGeneral.BluetoothError) => void
177
82
  /** 接口调用成功的回调函数 */
178
83
  success?: (
179
84
  result: SuccessCallbackResult,
180
85
  ) => void
181
86
  }
182
- interface SuccessCallbackResult extends General.CallbackResult {
87
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
183
88
  /** 设备服务列表 */
184
89
  services: BLEService[]
185
90
  /** 成功:ok,错误:详细信息 */
@@ -193,23 +98,6 @@ declare namespace Taro {
193
98
  uuid: string
194
99
  }
195
100
  }
196
- /** 获取蓝牙设备所有服务(service)。
197
- * @supported weapp
198
- * @example
199
- * ```tsx
200
- * Taro.getBLEDeviceServices({
201
- * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
202
- * deviceId,
203
- * success: function (res) {
204
- * console.log('device services:', res.services)
205
- * }
206
- * })
207
- * ```
208
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceServices.html
209
- */
210
- function getBLEDeviceServices(
211
- option: getBLEDeviceServices.Option,
212
- ): Promise<getBLEDeviceServices.SuccessCallbackResult>
213
101
 
214
102
  namespace getBLEDeviceCharacteristics {
215
103
  interface Option {
@@ -218,13 +106,13 @@ declare namespace Taro {
218
106
  /** 蓝牙服务 uuid,需要使用 `getBLEDeviceServices` 获取 */
219
107
  serviceId: string
220
108
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
221
- complete?: (res: General.BluetoothError) => void
109
+ complete?: (res: TaroGeneral.BluetoothError) => void
222
110
  /** 接口调用失败的回调函数 */
223
- fail?: (res: General.BluetoothError) => void
111
+ fail?: (res: TaroGeneral.BluetoothError) => void
224
112
  /** 接口调用成功的回调函数 */
225
113
  success?: (res: SuccessCallbackResult) => void
226
114
  }
227
- interface SuccessCallbackResult extends General.CallbackResult {
115
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
228
116
  /** 设备特征值列表 */
229
117
  characteristics: BLECharacteristic[]
230
118
  /** 成功:ok,错误:详细信息 */
@@ -249,28 +137,9 @@ declare namespace Taro {
249
137
  write: boolean
250
138
  }
251
139
  }
252
- /** 获取蓝牙设备某个服务中所有特征值(characteristic)。
253
- * @supported weapp
254
- * @example
255
- * ```tsx
256
- * Taro.getBLEDeviceCharacteristics({
257
- * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
258
- * deviceId,
259
- * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
260
- * serviceId,
261
- * success: function (res) {
262
- * console.log('device getBLEDeviceCharacteristics:', res.characteristics)
263
- * }
264
- * })
265
- * ```
266
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceCharacteristics.html
267
- */
268
- function getBLEDeviceCharacteristics(
269
- option: getBLEDeviceCharacteristics.Option,
270
- ): Promise<getBLEDeviceCharacteristics.SuccessCallbackResult>
271
140
 
272
141
  namespace createBLEConnection {
273
- interface Promised extends General.CallbackResult {
142
+ interface Promised extends TaroGeneral.CallbackResult {
274
143
  /** 成功:ok,错误:详细信息 */
275
144
  errMsg: string
276
145
  }
@@ -278,40 +147,18 @@ declare namespace Taro {
278
147
  /** 用于区分设备的 id */
279
148
  deviceId: string
280
149
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
281
- complete?: (res: General.BluetoothError) => void
150
+ complete?: (res: TaroGeneral.BluetoothError) => void
282
151
  /** 接口调用失败的回调函数 */
283
- fail?: (res: General.BluetoothError) => void
152
+ fail?: (res: TaroGeneral.BluetoothError) => void
284
153
  /** 接口调用成功的回调函数 */
285
- success?: (res: General.BluetoothError) => void
154
+ success?: (res: TaroGeneral.BluetoothError) => void
286
155
  /** 超时时间,单位ms,不填表示不会超时 */
287
156
  timeout?: number
288
157
  }
289
158
  }
290
- /** 连接低功耗蓝牙设备。
291
- *
292
- * 若小程序在之前已有搜索过某个蓝牙设备,并成功建立连接,可直接传入之前搜索获取的 deviceId 直接尝试连接该设备,无需进行搜索操作。
293
- *
294
- * **注意**
295
- * - 请保证尽量成对的调用 `createBLEConnection` 和 `closeBLEConnection` 接口。安卓如果多次调用 `createBLEConnection` 创建连接,有可能导致系统持有同一设备多个连接的实例,导致调用 `closeBLEConnection` 的时候并不能真正的断开与设备的连接。
296
- * - 蓝牙连接随时可能断开,建议监听 Taro.onBLEConnectionStateChange 回调事件,当蓝牙设备断开时按需执行重连操作
297
- * - 若对未连接的设备或已断开连接的设备调用数据读写操作的接口,会返回 10006 错误,建议进行重连操作。
298
- * @supported weapp
299
- * @example
300
- * ```tsx
301
- * Taro.createBLEConnection({
302
- * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
303
- * deviceId,
304
- * success: function (res) {
305
- * console.log(res)
306
- * }
307
- * })
308
- * ```
309
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.createBLEConnection.html
310
- */
311
- function createBLEConnection(option: createBLEConnection.Option): Promise<createBLEConnection.Promised>
312
159
 
313
160
  namespace closeBLEConnection {
314
- interface Promised extends General.CallbackResult {
161
+ interface Promised extends TaroGeneral.CallbackResult {
315
162
  /** 成功:ok,错误:详细信息 */
316
163
  errMsg: string
317
164
  }
@@ -319,30 +166,16 @@ declare namespace Taro {
319
166
  /** 用于区分设备的 id */
320
167
  deviceId: string
321
168
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
322
- complete?: (res: General.BluetoothError) => void
169
+ complete?: (res: TaroGeneral.BluetoothError) => void
323
170
  /** 接口调用失败的回调函数 */
324
- fail?: (res: General.BluetoothError) => void
171
+ fail?: (res: TaroGeneral.BluetoothError) => void
325
172
  /** 接口调用成功的回调函数 */
326
- success?: (res: General.BluetoothError) => void
173
+ success?: (res: TaroGeneral.BluetoothError) => void
327
174
  }
328
175
  }
329
- /** 断开与低功耗蓝牙设备的连接。
330
- * @supported weapp
331
- * @example
332
- * ```tsx
333
- * Taro.closeBLEConnection({
334
- * deviceId,
335
- * success: function (res) {
336
- * console.log(res)
337
- * }
338
- * })
339
- * ```
340
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.closeBLEConnection.html
341
- */
342
- function closeBLEConnection(option: closeBLEConnection.Option): Promise<closeBLEConnection.Promised>
343
176
 
344
177
  namespace writeBLECharacteristicValue {
345
- interface Promised extends General.CallbackResult {
178
+ interface Promised extends TaroGeneral.CallbackResult {
346
179
  /** 成功:ok,错误:详细信息 */
347
180
  errMsg: string
348
181
  }
@@ -356,44 +189,224 @@ declare namespace Taro {
356
189
  /** 蓝牙设备特征值对应的二进制值 */
357
190
  value: ArrayBuffer
358
191
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
359
- complete?: (res: General.BluetoothError) => void
192
+ complete?: (res: TaroGeneral.BluetoothError) => void
360
193
  /** 接口调用失败的回调函数 */
361
- fail?: (res: General.BluetoothError) => void
194
+ fail?: (res: TaroGeneral.BluetoothError) => void
362
195
  /** 接口调用成功的回调函数 */
363
- success?: (res: General.BluetoothError) => void
196
+ success?: (res: TaroGeneral.BluetoothError) => void
364
197
  }
365
198
  }
366
- /** 向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持 write 才可以成功调用。
367
- *
368
- * **注意**
369
- * - 并行调用多次会存在写失败的可能性。
370
- * - 小程序不会对写入数据包大小做限制,但系统与蓝牙设备会限制蓝牙4.0单次传输的数据大小,超过最大字节数后会发生写入错误,建议每次写入不超过20字节。
371
- * - 若单次写入数据过长,iOS 上存在系统不会有任何回调的情况(包括错误回调)。
372
- * - 安卓平台上,在调用 `notifyBLECharacteristicValueChange` 成功后立即调用 `writeBLECharacteristicValue` 接口,在部分机型上会发生 10008 系统错误
373
- * @supported weapp
374
- * @example
375
- * ```tsx
376
- * // 向蓝牙设备发送一个0x00的16进制数据
377
- * let buffer = new ArrayBuffer(1)
378
- * let dataView = new DataView(buffer)
379
- * dataView.setUint8(0, 0)
380
- * Taro.writeBLECharacteristicValue({
381
- * // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
382
- * deviceId,
383
- * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
384
- * serviceId,
385
- * // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
386
- * characteristicId,
387
- * // 这里的value是ArrayBuffer类型
388
- * value: buffer,
389
- * success: function (res) {
390
- * console.log('writeBLECharacteristicValue success', res.errMsg)
391
- * }
392
- * })
393
- * ```
394
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.writeBLECharacteristicValue.html
395
- */
396
- function writeBLECharacteristicValue(
397
- option: writeBLECharacteristicValue.Option,
398
- ): Promise<writeBLECharacteristicValue.Promised>
199
+
200
+ interface TaroStatic {
201
+ /** 读取低功耗蓝牙设备的特征值的二进制数据值。注意:必须设备的特征值支持 read 才可以成功调用。
202
+ *
203
+ * **注意**
204
+ * - 并行调用多次会存在读失败的可能性。
205
+ * - 接口读取到的信息需要在 `onBLECharacteristicValueChange` 方法注册的回调中获取。
206
+ * @supported weapp
207
+ * @example
208
+ * ```tsx
209
+ * // 必须在这里的回调才能获取
210
+ * Taro.onBLECharacteristicValueChange(function(characteristic) {
211
+ * console.log('characteristic value comed:', characteristic)
212
+ * })
213
+ * Taro.readBLECharacteristicValue({
214
+ * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
215
+ * deviceId,
216
+ * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
217
+ * serviceId,
218
+ * // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
219
+ * characteristicId,
220
+ * success: function (res) {
221
+ * console.log('readBLECharacteristicValue:', res.errCode)
222
+ * }
223
+ * })
224
+ * ```
225
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.readBLECharacteristicValue.html
226
+ */
227
+ readBLECharacteristicValue(
228
+ option: readBLECharacteristicValue.Option,
229
+ ): Promise<TaroGeneral.BluetoothError>
230
+
231
+ /** 监听低功耗蓝牙连接状态的改变事件。包括开发者主动连接或断开连接,设备丢失,连接异常断开等等
232
+ * @supported weapp
233
+ * @example
234
+ * ```tsx
235
+ * Taro.onBLEConnectionStateChange(function (res) {
236
+ * // 该方法回调中可以用于处理连接意外断开等异常情况
237
+ * console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)
238
+ * })
239
+ * ```
240
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.onBLEConnectionStateChange.html
241
+ */
242
+ onBLEConnectionStateChange(
243
+ /** 低功耗蓝牙连接状态的改变事件的回调函数 */
244
+ callback: onBLEConnectionStateChange.Callback,
245
+ ): void
246
+
247
+ /** 监听低功耗蓝牙设备的特征值变化事件。必须先启用 `notifyBLECharacteristicValueChange` 接口才能接收到设备推送的 notification。
248
+ * @supported weapp
249
+ * @example
250
+ * ```tsx
251
+ * // ArrayBuffer转16进制字符串示例
252
+ * function ab2hex(buffer) {
253
+ * let hexArr = Array.prototype.map.call(
254
+ * new Uint8Array(buffer),
255
+ * function(bit) {
256
+ * return ('00' + bit.toString(16)).slice(-2)
257
+ * }
258
+ * )
259
+ * return hexArr.join('');
260
+ * }
261
+ * Taro.onBLECharacteristicValueChange(function (res) {
262
+ * console.log(`characteristic ${res.characteristicId} has changed, now is ${res.value}`)
263
+ * console.log(ab2hex(res.value))
264
+ * })
265
+ * ```
266
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.onBLECharacteristicValueChange.html
267
+ */
268
+ onBLECharacteristicValueChange(
269
+ /** 低功耗蓝牙设备的特征值变化事件的回调函数 */
270
+ callback: onBLECharacteristicValueChange.Callback,
271
+ ): void
272
+
273
+ /** 启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。注意:必须设备的特征值支持 notify 或者 indicate 才可以成功调用。
274
+ *
275
+ * 另外,必须先启用 `notifyBLECharacteristicValueChange` 才能监听到设备 `characteristicValueChange` 事件
276
+ *
277
+ * **注意**
278
+ * - 订阅操作成功后需要设备主动更新特征值的 value,才会触发 Taro.onBLECharacteristicValueChange 回调。
279
+ * - 安卓平台上,在调用 `notifyBLECharacteristicValueChange` 成功后立即调用 `writeBLECharacteristicValue` 接口,在部分机型上会发生 10008 系统错误
280
+ * @supported weapp
281
+ * @example
282
+ * ```tsx
283
+ * Taro.notifyBLECharacteristicValueChange({
284
+ * state: true, // 启用 notify 功能
285
+ * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
286
+ * deviceId,
287
+ * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
288
+ * serviceId,
289
+ * // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
290
+ * characteristicId,
291
+ * success: function (res) {
292
+ * console.log('notifyBLECharacteristicValueChange success', res.errMsg)
293
+ * }
294
+ * })
295
+ * ```
296
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.notifyBLECharacteristicValueChange.html
297
+ */
298
+ notifyBLECharacteristicValueChange(
299
+ option: notifyBLECharacteristicValueChange.Option,
300
+ ): Promise<notifyBLECharacteristicValueChange.Promised>
301
+
302
+ /** 获取蓝牙设备所有服务(service)。
303
+ * @supported weapp
304
+ * @example
305
+ * ```tsx
306
+ * Taro.getBLEDeviceServices({
307
+ * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
308
+ * deviceId,
309
+ * success: function (res) {
310
+ * console.log('device services:', res.services)
311
+ * }
312
+ * })
313
+ * ```
314
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceServices.html
315
+ */
316
+ getBLEDeviceServices(
317
+ option: getBLEDeviceServices.Option,
318
+ ): Promise<getBLEDeviceServices.SuccessCallbackResult>
319
+
320
+ /** 获取蓝牙设备某个服务中所有特征值(characteristic)。
321
+ * @supported weapp
322
+ * @example
323
+ * ```tsx
324
+ * Taro.getBLEDeviceCharacteristics({
325
+ * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
326
+ * deviceId,
327
+ * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
328
+ * serviceId,
329
+ * success: function (res) {
330
+ * console.log('device getBLEDeviceCharacteristics:', res.characteristics)
331
+ * }
332
+ * })
333
+ * ```
334
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceCharacteristics.html
335
+ */
336
+ getBLEDeviceCharacteristics(
337
+ option: getBLEDeviceCharacteristics.Option,
338
+ ): Promise<getBLEDeviceCharacteristics.SuccessCallbackResult>
339
+
340
+ /** 连接低功耗蓝牙设备。
341
+ *
342
+ * 若小程序在之前已有搜索过某个蓝牙设备,并成功建立连接,可直接传入之前搜索获取的 deviceId 直接尝试连接该设备,无需进行搜索操作。
343
+ *
344
+ * **注意**
345
+ * - 请保证尽量成对的调用 `createBLEConnection` 和 `closeBLEConnection` 接口。安卓如果多次调用 `createBLEConnection` 创建连接,有可能导致系统持有同一设备多个连接的实例,导致调用 `closeBLEConnection` 的时候并不能真正的断开与设备的连接。
346
+ * - 蓝牙连接随时可能断开,建议监听 Taro.onBLEConnectionStateChange 回调事件,当蓝牙设备断开时按需执行重连操作
347
+ * - 若对未连接的设备或已断开连接的设备调用数据读写操作的接口,会返回 10006 错误,建议进行重连操作。
348
+ * @supported weapp
349
+ * @example
350
+ * ```tsx
351
+ * Taro.createBLEConnection({
352
+ * // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
353
+ * deviceId,
354
+ * success: function (res) {
355
+ * console.log(res)
356
+ * }
357
+ * })
358
+ * ```
359
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.createBLEConnection.html
360
+ */
361
+ createBLEConnection(option: createBLEConnection.Option): Promise<createBLEConnection.Promised>
362
+
363
+ /** 断开与低功耗蓝牙设备的连接。
364
+ * @supported weapp
365
+ * @example
366
+ * ```tsx
367
+ * Taro.closeBLEConnection({
368
+ * deviceId,
369
+ * success: function (res) {
370
+ * console.log(res)
371
+ * }
372
+ * })
373
+ * ```
374
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.closeBLEConnection.html
375
+ */
376
+ closeBLEConnection(option: closeBLEConnection.Option): Promise<closeBLEConnection.Promised>
377
+
378
+ /** 向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持 write 才可以成功调用。
379
+ *
380
+ * **注意**
381
+ * - 并行调用多次会存在写失败的可能性。
382
+ * - 小程序不会对写入数据包大小做限制,但系统与蓝牙设备会限制蓝牙4.0单次传输的数据大小,超过最大字节数后会发生写入错误,建议每次写入不超过20字节。
383
+ * - 若单次写入数据过长,iOS 上存在系统不会有任何回调的情况(包括错误回调)。
384
+ * - 安卓平台上,在调用 `notifyBLECharacteristicValueChange` 成功后立即调用 `writeBLECharacteristicValue` 接口,在部分机型上会发生 10008 系统错误
385
+ * @supported weapp
386
+ * @example
387
+ * ```tsx
388
+ * // 向蓝牙设备发送一个0x00的16进制数据
389
+ * let buffer = new ArrayBuffer(1)
390
+ * let dataView = new DataView(buffer)
391
+ * dataView.setUint8(0, 0)
392
+ * Taro.writeBLECharacteristicValue({
393
+ * // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
394
+ * deviceId,
395
+ * // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
396
+ * serviceId,
397
+ * // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
398
+ * characteristicId,
399
+ * // 这里的value是ArrayBuffer类型
400
+ * value: buffer,
401
+ * success: function (res) {
402
+ * console.log('writeBLECharacteristicValue success', res.errMsg)
403
+ * }
404
+ * })
405
+ * ```
406
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.writeBLECharacteristicValue.html
407
+ */
408
+ writeBLECharacteristicValue(
409
+ option: writeBLECharacteristicValue.Option,
410
+ ): Promise<writeBLECharacteristicValue.Promised>
411
+ }
399
412
  }